create GUI using pygtk and glade3

 

Here is a hello world code I write.

you can use gtk.builder to parse the glade source file, no longer need pyglade.

other uses are the same with pyglade.

#!/usr/bin/env python

#sytem imports
import pygtk
import gtk

#our own imports

glade_file = "helloGlade.glade"

class HelloGlade:
    
    def __init__(self):
        self.builder = gtk.Builder()
        self.builder.add_from_file(glade_file)

        self.window = self.builder.get_object("MainWindow")

        SIGNAL_CONNECTIONS_DIC = {
            "on_button1_clicked":
                self.button_clicked,
            "gtk_main_quit":
                lambda a1, a2: gtk.main_quit(),
        }

        self.builder.connect_signals(SIGNAL_CONNECTIONS_DIC)

    def button_clicked(self, widget):
        print 'button clicked'

    def main(self):
        self.window.show()
        gtk.main()
        return 0

if __name__ == "__main__":
    HelloGlade().main()

你可能感兴趣的:(object,File,Class,button,Signal,gtk)