In this video we’ll learn about Pack and Grid for placement with Tkinter and Python.

Pack and Grid are two very different ways to place widgets in Tkinter.

In this video we’ll learn how to use each, and also when to use each!

We’ll also look at a hack that allows you to use both pack and grid at the same time!

Python Code: pack_grid.py
(Github Code)

from tkinter import *

root = Tk()
root.title("Pack vs. Grid - Intro To Tkinter")
root.iconbitmap('images/tkinter.ico')
root.geometry('500x350')

# Pack some buttons
my_button1 = Button(root, text="Button")
my_button2 = Button(root, text="Button")

my_button1.pack(pady=(20,0))
my_button2.pack(pady=0, fill=X, padx=20)

# Create a quick frame
my_frame = Frame(root)
my_frame.pack(pady=50)

# Grid Stuff
my_button3 = Button(my_frame, text="Button")
my_button4 = Button(my_frame, text="Button")
my_button5 = Button(my_frame, text="Button")

my_button6 = Button(my_frame, text="Button")


my_button3.grid(row=0, column=0)
my_button4.grid(row=0, column=1, padx=20)
my_button5.grid(row=0, column=2)
my_button6.grid(row=1, column=0, pady=20, columnspan=3, sticky='ew')



root.mainloop()



John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...