Python-Ref > GUI programming with PyGTK > Glade UI designer > Hello GtkBuilder
 
 

<-^^
Klíčová slova
Moduly
Knihovní funkce
GTK Widgety

Hello GtkBuilder

GtkBuilder is a newer format and interface for GUI stored in XML. It is built into GTK, so no external libraries are required and it offers some features not present in the older Glade format - most importantly support for actions.
Expand/Shrink
Zdroj: (glade2-1.py)
  1   import pygtk
  2   pygtk.require("2.0")
  3   import gtk
  4   
  5   class HelloGtkBuilder(object):
  6   
  7     def __init__(self):
  8       self.builder = gtk.Builder()
  9       self.builder.add_from_file("infiles/hello_builder.ui") 
 10       self.builder.connect_signals(self)
 11       self.window = self.builder.get_object("window1")
 12       self.window.connect("destroy", gtk.main_quit)
 13       self.window.show()
 14   
 15     def on_button1_clicked(self, w):
 16       print "Button 1 clicked"
 17   
 18     def on_button2_clicked(self, w):
 19       print "Button 2 clicked"
 20   
 21   
 22   app = HelloGtkBuilder()
 23   gtk.main()
stdout:
Button 1 clicked
Button 2 clicked
Screenshot:
Program screenshot glade2-1.png
Doba běhu: 3066.3 ms