Copyright © tutorialspoint.com

Python - Tkinter pack() Method

previous next


This geometry manager organizes widgets in blocks before placing them in the parent widget.

Syntax:

widget.pack( pack_options )

Here is the list of possible options:

Example:

Try following example by moving cursor on different buttons:

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="Brown", fg="brown")
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()

This would produce following result:

TK Frame
previous next

Copyright © tutorialspoint.com