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

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

Frame

Simple widget for decoration and visual grouping of GUI elements.
The Frame widget provides a simple decoration that can be used to group together related parts of the GUI.
Expand/Shrink
Zdroj: (gtk-frame1-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( -1, -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.HBox()
 20       self.window.add( self.mainbox)
 21       # frame1
 22       frame1 = gtk.Frame( "Select file format:") 
 23       frame1.set_label_align( 0, 0.5) 
 24       self.mainbox.pack_start( frame1, padding=10)
 25       frame1.show()
 26       # fill frame1
 27       radio_box = self.create_radio_box()
 28       frame1.add( radio_box)
 29       radio_box.show()
 30       # frame2
 31       frame2 = gtk.Frame( "Options:") 
 32       frame2.set_label_align( 0.5, 1) 
 33       frame2.set_shadow_type( gtk.SHADOW_ETCHED_OUT) 
 34       self.mainbox.pack_end( frame2, padding=10)
 35       frame2.show()
 36       # fill frame2
 37       check_box = self.create_check_box()
 38       frame2.add( check_box)
 39       check_box.show()
 40       # show the box
 41       self.mainbox.show()
 42   
 43     def create_radio_box( self):
 44       radio_box = gtk.VBox()
 45       radio1 = gtk.RadioButton( None, "Python script")
 46       radio_box.pack_start( radio1, expand=False)
 47       radio1.show()
 48       for text in ["XML","HTML","Bash script"]:
 49         radio = gtk.RadioButton( radio1, text)
 50         radio_box.pack_start( radio, expand=False)
 51         radio.show()
 52       return radio_box
 53   
 54     def create_check_box( self):
 55       check_box = gtk.VBox()
 56       for text in ["Automatically add extension","Convert DOS newline characters","Convert to UTF-8"]:
 57         ch = gtk.CheckButton( text)
 58         ch.show()
 59         check_box.pack_start( ch, expand=False)
 60       return check_box
 61   
 62     def main( self):
 63       gtk.main()
 64   
 65     def destroy( self, w):
 66       gtk.main_quit()
 67   
 68   
 69   if __name__ == "__main__":
 70     m = MyGUI( "Frames")
 71     m.main()
Screenshot:
Program screenshot gtk-frame1-1.png
Doba běhu: 776.7 ms
Expand/Shrink
Rozdíl proti: gtk-frame1-1.py
@@ -10,17 +10,18 @@
     self.window = gtk.Window()
     self.title = title
     self.window.set_title( title)
-    self.window.set_size_request( -1, -1)
+    self.window.set_size_request( 260, -1)
     self.window.connect( "destroy", self.destroy)
     self.create_interior()
     self.window.show_all()
   def create_interior( self):
-    self.mainbox = gtk.HBox()
+    self.mainbox = gtk.VBox()
     self.window.add( self.mainbox)
     # frame1
     frame1 = gtk.Frame( "Select file format:") 
     frame1.set_label_align( 0, 0.5) 
+    frame1.set_shadow_type( gtk.SHADOW_IN) 
     self.mainbox.pack_start( frame1, padding=10)
     frame1.show()
     # fill frame1
@@ -30,7 +31,7 @@
     # frame2
     frame2 = gtk.Frame( "Options:") 
     frame2.set_label_align( 0.5, 1) 
-    frame2.set_shadow_type( gtk.SHADOW_ETCHED_OUT) 
+    frame2.set_shadow_type( gtk.SHADOW_OUT) 
     self.mainbox.pack_end( frame2, padding=10)
     frame2.show()
     # fill frame2
Screenshot:
Program screenshot gtk-frame1-2.png
Doba běhu: 1208.2 ms