The document provides an overview of layout management in Python's Tkinter library, focusing on the Pack layout method. It explains how to control widget placement, add padding, fill space, and expand widgets using various options. Additionally, it includes examples of combining options for more precise layout control.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views
Layout Python
The document provides an overview of layout management in Python's Tkinter library, focusing on the Pack layout method. It explains how to control widget placement, add padding, fill space, and expand widgets using various options. Additionally, it includes examples of combining options for more precise layout control.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15
Layout Python
By Dr. Chit Su Hlaing
Common Layout • Pack =>side • Grid => row column • Place => x, y coordinates Using the Pack Layout • The pack() method is used to arrange widgets. • By default, widgets are placed from top to bottom. • In this example, three labels are stacked vertically in the window by default, since pack() organizes widgets from top to bottom. Controlling the Packing Direction • control the direction and placement of widgets using the side parameter. • The options are: • side=tk.TOP (default) • side=tk.BOTTOM • side=tk.LEFT • side=tk.RIGHT Padding (Internal and External) • add padding to widgets using • label1.pack(side=tk.TOP, pady=10) # padx, pady, ipadx, and ipady. External padding of 10 units vertically • padx and pady add external • label2.pack(side=tk.BOTTOM, padx=5) # padding. External padding of 5 units horizontally • ipadx and ipady add internal • label3.pack(side=tk.LEFT, ipadx=20, padding. ipady=20) # Internal padding Filling Space • The fill option allows widgets to • label1.pack(fill=tk.X) # Expand expand and fill available space. horizontally • fill=tk.X: Expands the widget • label2.pack(fill=tk.Y) # Expand horizontally. vertically • fill=tk.Y: Expands the widget • label3.pack(fill=tk.BOTH, vertically. expand=True) # Expand both • fill=tk.BOTH: Expands the widget horizontally and vertically in both directions. Expanding Widgets • The expand option allows • label1.pack(side=tk.TOP, widgets to take up extra space in fill=tk.X, expand=True) # Fills the window if available. horizontally and expands to fill • It works with fill. space • label2.pack(side=tk.BOTTOM, fill=tk.X, expand=True) # Fills horizontally and expands • label3.pack(side=tk.LEFT, fill=tk.Y, expand=True) # Fills vertically and expands Combining Options • combine options to get more control over the layout. • label1.pack(side=tk.TOP, fill=tk.X, padx=5, pady=5) # Expands horizontally with padding • label2.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) # Expands in both directions • label3.pack(side=tk.RIGHT, fill=tk.Y, expand=True, ipadx=10, ipady=10) # Expands vertically with internal padding • Frame • Name Frame (name label, name entry box) • Age Frame (age label, age entry box) • Create student button • Frame • NameFrame.pack() • ageFrame.pack() • Button.pack() Search Student Information