How it works…

To have a better understanding of the Pack geometry manager, we will explain step by step how it adds widgets to the parent container. Here, we pay special attention to the values of the side option, which indicates, the relative position of the widget with respect to the next one that will be packed.

First, we pack the two labels at the top of the screen. While the tk.TOP constant is the default value of the side option, we set it explicitly to clearly differentiate it from the calls where we used the tk.LEFT value:

Then, we pack the next three labels with the side option set to tk.LEFT, which causes them to be placed side by side:

Specifying the side on label_e does not really matter, as long as it is the last widget we add to the container.

Keep in mind that this is the reason why order is so important when working with the Pack geometry manager. To prevent unexpected results in complex layouts, it is common to group widgets with frames so that when you pack all the widgets within a frame, you do not interfere with the arrangement of the other ones.

In these cases, we strongly recommend that you use the Grid geometry manager since it allows you to directly set the position of each widget with one call to the geometry manager and avoids the need for additional frames.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset