Python Glade could not create GladeXML Object

前端 未结 2 1668
野趣味
野趣味 2020-12-31 06:35

I\'ve created a simple window GUI in Glade 3.6.7 and I am trying to import it into Python. Every time I try to do so I get the following error:

(queryrelevan         


        
相关标签:
2条回答
  • 2020-12-31 07:13

    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

    0 讨论(0)
  • 2020-12-31 07:29

    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!!!!

    0 讨论(0)
提交回复
热议问题