How to Build User Interfaces with Python — Tkinter Layouts

Esteban Thilliez
Tech Tavern
Published in
5 min readSep 23, 2022

--

How to Build User Interfaces with Python — Tkinter Layouts
Photo by Hal Gatewood on Unsplash

This story follows the User Interfaces series. If you have missed the first Tkinter story, you can find it here:

Layouts are very important when building UI because they allow you to display the elements as you want, in a structured way. You can specify the positions of widgets inside a top-level or parent window.

Tkinter provides 3 layout managers, we’ll discover each of them.

The base code for this story will be:

import tkinter as tk


main_window = tk.Tk()
main_window.title("Layouts")
main_window.geometry("400x400")

label1 = tk.Label(main_window, text="Label 1", bg="red")
label2 = tk.Label(main_window, text="Label 2", bg="green")
...main_window.mainloop()

pack

It’s the first layout manager we have discovered in Tkinter (if you have followed my series). In the first story, we used pack without parameters. But we can customize our widgets by providing some parameters to pack .

--

--

Esteban Thilliez
Tech Tavern

I’m Esteban, and I enjoy writing about programming, trading, productivity, knowledge management, books, etc! esteban-thilliez.com / contact@esteban-thilliez.com