putting glade interface in python

后端 未结 5 532
别跟我提以往
别跟我提以往 2021-02-06 02:30

I\'ve made a gui in glade that I want to put in a python program. I was adapting the instructions from a tutorial I found online to load in my glade file (http://www.pygtk.org/a

5条回答
  •  误落风尘
    2021-02-06 02:47

    Try with this code:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import pygtk
    pygtk.require("2.0")
    import gtk
    import gtk.glade
    
    class HellowWorldGTK:
    
        def __init__(self):
            self.gladefile = "helloworld.glade" 
            self.glade = gtk.Builder()
            self.glade.add_from_file(self.gladefile)
            self.glade.connect_signals(self)
            self.glade.get_object("MainWindow").show_all()
    
        def on_MainWindow_delete_event(self, widget, event):
            gtk.main_quit()
    
    if __name__ == "__main__":
        try:
            a = HellowWorldGTK()
            gtk.main()
        except KeyboardInterrupt:
            pass
    

    Remember: In Glade, Edit the "Preferences" of the file to "GTKBuilder" (not "libglade")

提交回复
热议问题