As a Python developer, I have found the Grid layout system to be an essential tool for building professional-looking applications. Throughout this article, I will explain how to create responsive layouts with Python Tkinter’s grid geometry manager with detailed examples and share my experience to help you master the Tkinter Grid.
Create Responsive Layouts with Python Tkinter’s Grid Geometry Manager
Tkinter’s Grid geometry manager allows you to arrange widgets in a table-like structure, defined by rows and columns. Each widget is assigned to a specific cell within the grid, making it easy to create clean and organized layouts. The Grid system is highly flexible and responsive, adapting to window resizing and content changes.
To use the Grid layout, you simply need to call the .grid() method on your widgets. For example:
from tkinter import *
root = Tk()
my_label = Label(root, text="Hello, John from New York!")
my_label.grid(row=0, column=0)
root.mainloop()You can look at the output in the screenshot below.

In this example, we create a simple label widget and place it in the grid’s first cell (row 0, column 0).
Read How to Create Labels in Python with Tkinter?
1. Configure Rows and Columns
One of the key advantages of the Grid system is its ability to automatically adjust the size of rows and columns based on their contents. Tkinter provides several options to configure the behavior of rows and columns:
rowconfigure(index, weight=1): This method allows you to set the weight of a specific row. The weight determines how the extra space is distributed among rows when the window is resized. A higher weight means the row will expand more compared to others.columnconfigure(index, weight=1): Similar torowconfigure(), this method sets the weight for a specific column.
Here’s an example that demonstrates how to configure rows and columns:
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=2)
root.columnconfigure(0, weight=1)You can look at the output in the screenshot below.

In this case, the second row (index 1) will expand twice as much as the first row (index 0) when the window is resized vertically. The column will expand proportionally in the horizontal direction.
Check out How to Create Labels in Python with Tkinter?
2. Span Widgets Across Multiple Cells
Sometimes, you may want a widget to occupy multiple cells in the grid. Tkinter allows you to achieve this using the columnspan and rowspan parameters in the .grid() method.
Let’s say we have a user registration form for a website targeting the USA audience. We can use the Grid system to create a visually appealing layout:
from tkinter import *
root = Tk()
name_label = Label(root, text="Name:")
name_label.grid(row=0, column=0, sticky="E")
name_entry = Entry(root)
name_entry.grid(row=0, column=1, columnspan=2, sticky="WE")
email_label = Label(root, text="Email:")
email_label.grid(row=1, column=0, sticky="E")
email_entry = Entry(root)
email_entry.grid(row=1, column=1, columnspan=2, sticky="WE")
state_label = Label(root, text="State:")
state_label.grid(row=2, column=0, sticky="E")
state_var = StringVar(value="California")
state_dropdown = OptionMenu(root, state_var, "California", "Texas", "Florida", "New York")
state_dropdown.grid(row=2, column=1, sticky="W")
submit_button = Button(root, text="Submit")
submit_button.grid(row=3, column=1, columnspan=2, sticky="E")
root.mainloop()You can look at the output in the screenshot below.

In this example, the name and email entry fields span across two columns using columnspan=2. The submit button also spans two columns to align it properly. The sticky parameter is used to control how the widgets are aligned within their cells.
Read How to Create Buttons in Python with Tkinter?
3. Align Widgets within Cells
The sticky parameter in the .grid() method allows you to control the alignment of widgets within their assigned cells. It accepts a string of cardinal directions: “N” (North), “S” (South), “E” (East), “W” (West), or a combination of them.
For example, sticky="NS" will make the widget expand and fill the cell vertically, while sticky="WE" making it expand horizontally. You can also combine directions, such as sticky="NSEW" , to make the widget fill the entire cell.
Here’s an example that demonstrates widget alignment:
from tkinter import *
root = Tk()
header_label = Label(root, text="Customer Information", font=("Arial", 16))
header_label.grid(row=0, column=0, columnspan=2, sticky="W", padx=10, pady=10)
name_label = Label(root, text="Name:")
name_label.grid(row=1, column=0, sticky="E", padx=5, pady=5)
name_entry = Entry(root)
name_entry.grid(row=1, column=1, sticky="WE", padx=5, pady=5)
address_label = Label(root, text="Address:")
address_label.grid(row=2, column=0, sticky="NE", padx=5, pady=5)
address_text = Text(root, height=3)
address_text.grid(row=2, column=1, sticky="NSEW", padx=5, pady=5)
root.columnconfigure(1, weight=1)
root.mainloop()You can look at the output in the screenshot below.

In this example, the header label is aligned to the left using sticky="W". The name label is aligned to the right using sticky="E" , while the name entry field expands horizontally. The address label is aligned to the top-right corner using sticky="NE" , and the address text area fills its cell.
Check out How to Create a Menu Bar in Tkinter?
4. Handle Complex Layouts with Frames
When creating complex user interfaces, it’s often helpful to break down the layout into smaller, more manageable sections using frames. Frames act as containers for other widgets and can be arranged using the Grid system just like any other widget.
Let’s consider an example of a customer relationship management (CRM) application for a USA-based company:
from tkinter import *
root = Tk()
# Customer Details Frame
customer_frame = LabelFrame(root, text="Customer Details")
customer_frame.grid(row=0, column=0, padx=10, pady=10, sticky="NSEW")
name_label = Label(customer_frame, text="Name:")
name_label.grid(row=0, column=0, sticky="E", padx=5, pady=5)
name_entry = Entry(customer_frame)
name_entry.grid(row=0, column=1, sticky="WE", padx=5, pady=5)
email_label = Label(customer_frame, text="Email:")
email_label.grid(row=1, column=0, sticky="E", padx=5, pady=5)
email_entry = Entry(customer_frame)
email_entry.grid(row=1, column=1, sticky="WE", padx=5, pady=5)
customer_frame.columnconfigure(1, weight=1)
# Interaction History Frame
history_frame = LabelFrame(root, text="Interaction History")
history_frame.grid(row=1, column=0, padx=10, pady=10, sticky="NSEW")
history_text = Text(history_frame)
history_text.pack(fill=BOTH, expand=True)
# Configure root grid
root.columnconfigure(0, weight=1)
root.rowconfigure(1, weight=1)
root.mainloop()You can look at the output in the screenshot below.

In this example, we create two frames: one for customer details and another for interaction history. The customer details frame uses the Grid system to arrange labels and entry fields, while the interaction history frame uses the Pack geometry manager to simplify the layout.
Read How to Use Tkinter Entry Widget in Python?
Grid Padding
While organizing a widget at times the default size or position of the widget didn’t meet the expectations. At that time using padding, we can adjust the widget. There are two types of padding: Padding inside the widget’s border and padding outside the widget’s border. ipadx, and ipady are used to add spaces horizontally and vertically inside the widget’s border. padx, and pady are used to add spaces horizontally and vertically outside the widget’s border.
from tkinter import *
ws = Tk()
ws.title('PythonGuides')
ws.geometry('400x300')
ws.config(bg='#F2B33D')
frame = Frame(ws, bg='#F2B33D')
Button(frame, text="7").grid(row=0, column=0, sticky='ew')
Button(frame, text="8").grid(row=0, column=1)
Button(frame, text="9").grid(row=0, column=2)
Button(frame, text="4 ").grid(row=1, column=0)
Button(frame, text="5").grid(row=1, column=1, ipadx=10, ipady=10, padx=10, pady=10)
Button(frame, text="6").grid(row=1, column=2)
Button(frame, text="7 ").grid(row=2, column=0)
Button(frame, text="8").grid(row=2, column=1)
Button(frame, text="9").grid(row=2, column=2)
frame.pack(expand=True)
ws.mainloop()We have added ipadx=10 and ipady=10, with this 10 pixels are added inside the widget’s border and it has started looking bigger.
Check out How to Create Checkboxes in Python Tkinter?
Best Practices and Tips
Here are some best practices and tips to keep in mind when using Tkinter’s Grid geometry manager:
- Plan your layout: Before starting to code, sketch out your desired layout on paper or using a design tool. This will help you visualize the structure and identify the necessary rows, columns, and widgets.
- Use meaningful variable names: Choose descriptive names for your widgets and variables to enhance code readability and maintainability.
- Utilize frames: Break down complex layouts into logical sections using frames. This makes your code more modular and easier to understand.
- Be consistent with padding: Use the
padxandpadyparameters consistently to create a visually balanced layout with appropriate spacing between widgets. - Test responsiveness: Resize your application window to ensure that the layout remains functional and visually appealing at different sizes.
- Consider using themed widgets: Tkinter provides themed widget libraries, such as
ttkbootstrapandcustomtkinter, which offers a more modern and polished look compared to the default Tkinter widgets.
Check out How to Create and Customize Listboxes in Python Tkinter?
Conclusion
In this tutorial, I have explained create responsive layouts with Python Tkinter’s grid geometry manager. I discussed creating a simple label widget and added configurations like rows , columns, span widgets across multiple cells, and handling complex layouts with frames. I also discussed grid padding and some best practices and tips.
You may like to read:
- How to Create Radio Buttons in Python with Tkinter?
- How to use Tkinter Filedialog in Python
- Expense Tracking Application Using Python Tkinter

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.