Python-Ref > GUI programming with PyGTK > Widgets > Labels
 
 

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

Labels

How to add simple text into your GUI.
The following code shows some basic features of Labels - simple text-display widgets.
Expand/Shrink
Zdroj: (gtk6-1.py)
  1   # ensure that PyGTK 2.0 is loaded - not an older version
  2   import pygtk
  3   pygtk.require('2.0')
  4   # import the GTK module
  5   import gtk
  6   
  7   class MyGUI:
  8   
  9     def __init__( self, title):
 10       self.window = gtk.Window()
 11       self.title = title
 12       self.window.set_title( title)
 13       self.window.set_size_request( 300, -1)
 14       self.window.connect( "destroy", self.destroy)
 15       self.create_interior()
 16       self.window.show_all()
 17   
 18     def create_interior( self):
 19       self.mainbox = gtk.VBox()
 20       self.window.add( self.mainbox)
 21       # normal label
 22       l1 = gtk.Label( "This is sample Label nr. 1")
 23       self.add_to_mainbox_and_show( l1)
 24       # label with undelined letter - used in menus and buttons
 25       l2 = gtk.Label( "_This is sample Label nr. 2")
 26       l2.set_use_underline( True)
 27       self.add_to_mainbox_and_show( l2)
 28       # label with markup
 29       l3 = gtk.Label()
 30       l3.set_markup( "<b>This</b> is sample <i>Label</i> nr. 3")
 31       self.add_to_mainbox_and_show( l3)
 32       # selectable label
 33       l4 = gtk.Label( "This is sample Label nr. 4")
 34       l4.set_selectable( True)
 35       self.add_to_mainbox_and_show( l4)
 36       # show the main box
 37       self.mainbox.show()
 38   
 39     def add_to_mainbox_and_show( self, w):
 40       self.mainbox.pack_start( w, padding=3)
 41       w.show()
 42   
 43     def main( self):
 44       gtk.main()
 45   
 46     def destroy( self, w):
 47       gtk.main_quit()
 48   
 49   
 50   if __name__ == "__main__":
 51     m = MyGUI( "Hello Boxes")
 52     m.main()
Screenshot:
Program screenshot gtk6-1.png
Doba běhu: 4391.5 ms