Hello dear readers! welcome back to another section of our tutorial on Python. In this tutorial post, we are going to be discussing about the Python Tkinter pack() Method.
The Python Tkinter pack() geometry manager arranges widgets in blocks before placing them all in the parent widget.
The Python Tkinter pack() geometry manager arranges widgets in blocks before placing them all in the parent widget.
Syntax
The following below is the syntax for this method -
widget.pack( pack_options )
Options
Below is the list of possible options -
- expand - when set to true, the widget expands to fill any space not that is not used in widget's parent.
- fill - Determines whether widget fills any extra space allocated to it by the packer, or preserves its own minimal dimensions.
- side - Determines which side of the parent widget packs against.
RECOMMENDED: Python Tkinter LabelFrame Widget
Example
Try the following example below -
from Tkinter import * root = Tk() frame = Frame(root) frame.pack() bottomframe = Frame(root) bottomframe.pack( side = BOTTOM ) redbutton = Button(frame, text="Red", fg="red") redbutton.pack( side = LEFT) greenbutton = Button(frame, text="green", fg="green") greenbutton.pack( side = LEFT ) bluebutton = Button(frame, text="Blue", fg="blue") bluebutton.pack( side = LEFT ) blackbutton = Button(bottomframe, text="Black", fg="black") blackbutton.pack( side = BOTTOM) root.mainloop()
Output
When the above code is executed, it will produce the following result -
RECOMMENDED: Python Tkinter Cursors
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the Python Tkinter grid() Method.
Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.