How to do it...

Here, we will create a top-level frame that will contain other frames and widgets. This will help us get our GUI layout just the way we want.

In order to do so, we will have to embed our current controls within a central frame called ttk.LabelFrame. This frame ttk.LabelFrame is the child of the main parent window and all controls will be the children of this ttk.LabelFrame.

Up to this point in our recipes, we had assigned all widgets to our main GUI frame directly. Now, we will only assign LabelFrame to our main window and after that, we will make this LabelFrame the parent container for all the widgets.

This creates the following hierarchy in our GUI layout:

In the preceding diagram, win is the variable that holds a reference to our main GUI tkinter window frame, mighty is the variable that holds a reference to our LabelFrame and is a child of the main window frame (win), and Label and all other widgets are now placed into the LabelFrame container (mighty).

Add the following code towards the top of our Python module:

GUI_embed_frames.py

Next, we will modify the following controls to use mighty as the parent, replacing win. Here is an example of how to do this:

This results in the following GUI:

Note how all the widgets are now contained in the Mighty Python LabelFrame which surrounds all of them with a barely visible thin line. Next, we can reset the Labels in a Frame widget to the left without messing up our GUI layout:

GUI_embed_frames_align.py

Oops - maybe not. While our frame within another frame aligned nicely to the left, it again pushed our top widgets to the center (a default).

In order to align them to the left, we have to force our GUI layout by using the sticky property. By assigning it 'W' (West), we can control the widget to be left-aligned:

GUI_embed_frames_align_west.py

This results in the following GUI:

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

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