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

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

Hello world in GTK

The simplest possible GTK program
The code below shows a very simple Hello world! example. This program is in fact so simple that it cannot stop itself - you have to kill it manually.
Expand/Shrink
Zdroj: (gtk1-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   # show the window
  9   window.show_all()
 10   # enter the gtk mainloop - it runs purely on signals from now on
 11   gtk.main()
Screenshot:
Program screenshot gtk1-1.png
Doba běhu: 13338.1 ms
The following example contains just one line of code more to allow for closing of the application using the buttons in the upper right (usually) corner of the window.
Expand/Shrink
Zdroj: (gtk1-2.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   # connect the "destroy" event to the gtk.main_quit function
  9   # this allows closing the application using the window button "x"
 10   window.connect("destroy",gtk.main_quit)
 11   # show the window
 12   window.show_all()
 13   # enter the gtk mainloop - it runs purely on signals from now on
 14   gtk.main()
Screenshot:
Program screenshot gtk1-2.png
Doba běhu: 4201.1 ms