Layout Managers in Python GUI – Pack, Grid and Place

Hello everyone, welcome back to programminginpython.com. Here in this post, I am going to explain you about different layout managers Python GUI package TKInter has. In my previous posts, Temperature Converter app and Simple Calculator app where I created some Python GUI applications, I used either pack manager or grid manager. And there is one more layout manager called place manager.

You can watch the video on youtube here

However, in this post, I am going to cover all these three, pack, grid, and place managers with a simple example for each one of it and also will explain to you which layout manager to use based on different requirements.

Program on Github

Different Layout Managers in Python’s TKInter GUI package

Pack Manager

pack is one of the oldest and most used layout manager in Python’s TKInter package. It is very easy to style and place the widgets in an app using this pack() manager. When you use this pack() method on a widget, you don’t need to explicitly specify the position of that widget, pack automatically places the widget in window based upon the space available in the window.

You can use pack when your layout only consists of a group of items all aligned horizontally or vertically, mostly in case of a navigation menu or something like that.

This pack() has 3 options to use they are: fill, expand, and side. I will create a simple example to demonstrate this pack manager.

I will use fill option to align three labels vertically.

Use side option to align them horizontally.

Expand operation to take up the full height until the content ends. We use listbox widget to fill up space.

Pack Manager Example:

Program on Github

Python GUI Layout Managers - programminginpython.com
Python GUI Layout Managers – programminginpython.com

Grid Manager

grid is one of the most flexible layout manager out of the three GUI layout managers in python. It was introduced as an alternative to pack. Grid allows you to position the elements in rows and columns which give you more flexibility to your widgets.

I will create a simple 2×2 table like structure using grid’s rows and column way.

Program on Github

Python GUI Layout Managers - programminginpython.com
Python GUI Layout Managers – programminginpython.com

Place Manager

place is the most complex manager out of the 3 managers. It uses absolute positioning, when you choose place as your layout manager, then you need to specify the widgets positioning using x and y coordinates, When using this layout manager the size and position of the widgets do not change while resizing the window.

I will create a simple 4 lables which I will position based upon x and y coordinates.

Python GUI Layout Managers - programminginpython.com
Python GUI Layout Managers – programminginpython.com

Program on Github

That is all about Python GUI Layout managers pack, grid, and place.

Please feel free to look at my other posts on Python GUI programs.

One Comment

  1. Pingback: Milana Travis

Leave a Reply