Python-Ref > GUI programming with PyGTK > Introduction > Hello world in GTK II.
 
 

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

Hello world in GTK II.

A more elaborate example of Hello world.
The following Hello world example uses a Label to create a simple text inside the window. The window can have only one child and it resizes itself to accommodate it.
Expand/Shrink
Zdroj: (gtk2-1.py)
  1   # import the GTK module
  2   import gtk
  3   
  4   # create a new window
  5   window = gtk.Window()
  6   # set the title for the window
  7   window.set_title( "Hello world!")
  8   # create a label
  9   label = gtk.Label( "Hello world!")
 10   # add the label to the window
 11   window.add( label)
 12   # show the label
 13   label.show()
 14   # connect the "destroy" event to the gtk.main_quit function
 15   # this allows closing the application using the window button "x"
 16   window.connect("destroy",gtk.main_quit)
 17   # show the window
 18   window.show_all()
 19   # enter the gtk mainloop - it runs purely on signals from now on
 20   gtk.main()
Screenshot:
Program screenshot gtk2-1.png
Doba běhu: 7660.4 ms
When we need to add more than one item into the window (which we usually do), we have to use some container as the windows child and then add our items into the container. This approach is demonstrated here.