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

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

Paned

Widgets allowing separation of window to two parts of adjustable size.
Expand/Shrink
Zdroj: (gtk-hpaned1-1.py) přispěl(a) Josef Glemba
  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   
  8   class MyGUI:
  9   
 10     def __init__( self, title):
 11       self.window = gtk.Window()
 12       self.title = title
 13       self.window.set_title( title)
 14       self.window.set_size_request( 400, 300)
 15       self.window.connect( "destroy", self.destroy)
 16       self.create_interior()
 17       self.window.show_all()
 18       
 19     def create_interior( self):
 20       # hpaned widget
 21       hpaned = gtk.HPaned()
 22       self.window.add(hpaned)
 23       hpaned.show()  
 24       
 25       # fill the two parts, childs must be widgets
 26       #1
 27       self.label = gtk.Label("This is part 1..")
 28       hpaned.pack1(self.label, resize=True,shrink=True)
 29       
 30       #2
 31       textview = gtk.TextView()
 32       textbuffer = textview.get_buffer()
 33       textbuffer.set_text( "This is part 2..You can write here")
 34       hpaned.pack2(textview, resize=True, shrink=False)    
 35       
 36     def main( self):
 37       gtk.main()
 38   
 39     def destroy( self, w):
 40       gtk.main_quit()    
 41         
 42   if __name__ == "__main__":
 43     m = MyGUI( "Hpaned")
 44     m.main()
Screenshot:
Program screenshot gtk-hpaned1-1.jpg
Doba běhu: 1521.2 ms
Expand/Shrink
Zdroj: (gtk-vpaned1-1.py) přispěl(a) Josef Glemba
  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( 400, 300)
 14       self.window.connect( "destroy", self.destroy)
 15       self.create_interior()
 16       self.window.show_all()
 17       
 18     def create_interior( self):
 19       # vpaned widget
 20       vpaned = gtk.VPaned()
 21       self.window.add(vpaned)
 22       vpaned.show()  
 23       
 24       # set the divider
 25       vpaned.set_position(100)
 26       
 27       # fill the two parts, childs must be widgets  
 28       # 1    
 29       textview = gtk.TextView()
 30       textbuffer = textview.get_buffer()   
 31       textbuffer.set_text("Text.." )    
 32       vpaned.add1(textview)
 33       
 34       #2
 35       label = gtk.Label( vpaned.get_child1())    
 36       vpaned.add2(label)
 37       
 38       # test, adding another widget doesnt work
 39       label1 = gtk.Label("ANOTHER LABEL, do you see me??")
 40       vpaned.add2(label1)
 41       
 42     def main( self):
 43       gtk.main()
 44   
 45     def destroy( self, w):
 46       gtk.main_quit()
 47       
 48   if __name__ == "__main__":
 49     m = MyGUI( "Vpaned")
 50     m.main()
Screenshot:
Program screenshot gtk-vpaned1-1.jpg
Doba běhu: 500.2 ms