The difference between mesh and package geometry managers

What is the main difference between Tkinter grid and pack geometry managers?

What do you use for your projects?

If grid better to align the object, what is the main purpose of the pack ?

+7
python layout tkinter
source share
1 answer

grid is used to lay out widgets in a grid. Another answer says that “overlays the graph”, which is a bit wrong. It doesn’t impose anything; it simply arranges the widgets along the boundaries of rows and columns. It is great for creating tables and other structured layout types.

pack puts things on the sides of the box. It is highlighted when creating layouts where everything is on the same line or in the same column (think of the lines of buttons on the toolbar or in the dialog box). It is also useful for very simple layouts such as the navigator on the left and the main workspace on the right. It can be used to create very complex layouts, but it becomes complicated until you fully understand the packaging algorithm.

You cannot use both a grid and a package with widgets that have a common parent. Your application may work, but it is much more likely that it will end up in an endless loop, as each manager tries to expand the widgets and the other notes that the widgets are resizing and trying to customize, etc. Etc.

The third option is place . The place is great for absolute positioning (i.e.: place the widget at the given x / y) or relative (for example: place the widget on the right edge of some other widget).

As long as you cannot mix the grid and the package in one container (the container is usually a frame), you can use both the grid and the package in one application. This is very, very often, as each has its own strengths and weaknesses. I use both on a regular basis.

+18
source share

All Articles