Pack layout manager demonstration. : Layout « Tkinker « Python Tutorial






Pack layout manager demonstration.
from Tkinter import *

class PackDemo( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.master.title( "Packing Demo" )
      self.master.geometry( "400x150" )
      self.pack( expand = YES, fill = BOTH )

      self.button1 = Button( self, text = "Add Button",command = self.addButton )

      self.button1.pack( side = TOP )

      self.button2 = Button( self,text = "expand = NO, fill = BOTH" )

      self.button2.pack( side = BOTTOM, fill = BOTH )

      self.button3 = Button( self,text = "expand = YES, fill = X" )

      self.button3.pack( side = LEFT, expand = YES, fill = X )

      self.button4 = Button( self,text = "expand = YES, fill = Y" )

      self.button4.pack( side = RIGHT, expand = YES, fill = Y )   

   def addButton( self ):
      Button( self, text = "New Button" ).pack( pady = 5 )
      
PackDemo().mainloop()








18.18.Layout
18.18.1.Pack to TOP and RIGHTPack to TOP and RIGHT
18.18.2.Grid layoutGrid layout
18.18.3.Pack leftPack left
18.18.4.Pack layout manager demonstration.Pack layout manager demonstration.
18.18.5.Grid layout manager demonstration.Grid layout manager demonstration.
18.18.6.Demonstrates text and entry widgets, and the grid layout managerDemonstrates text and entry widgets, and the grid layout manager
18.18.7.Simple 2d tableSimple 2d table
18.18.8.2d table of input fields2d table of input fields