Python Glade could not create GladeXML Object

可紊 提交于 2019-11-30 08:31:58

You have created a GtkBuilder file instead of Glade file.

You can use GtkBuilder as follow:

builder = gtk.Builder()
builder.add_from_string(string, len(string))
builder.connect_signals(anobject)
builder.get_object(name)

EDIT:

When you start a new project in glade it asks you if you want create a glade file or a GtkBuilder file, which is new and more flexible. Try the builder file with the following code:

#!/usr/bin/env python

import gtk

class  QueryRelevanceEvaluationApp:

    def __init__(self):
        filename = "foo.glade"
        builder = gtk.Builder()
        builder.add_from_file(filename)
        builder.connect_signals(self)

    def on_buttonGenerate_clicked(self, widget):
        print "You clicked the button"

app = QueryRelevanceEvaluationApp()
gtk.main()

EDIT2:

Beware that i cannot see any handler in your GtkBuilder file

I had the same problem Pete mentioned. After the answer that mg gave, what I did is to save the .glade file in a liblgade format instead of GTKBuilder. On the Save As.. dialog box, at the bottom you have the option "File Format" click on "liblglade" and voila!!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!