How to do it...

Create a new Python module and place the following code into this module:

GUI_tabbed.py

This creates the following GUI:

While not amazingly impressive as of yet, this widget adds another very powerful tool to our GUI design toolkit. It comes with its own limitations in the minimalist example above (for example, we can neither reposition the GUI nor does it show the entire GUI title).

While we used the grid layout manager for simpler GUIs in the previous recipes, we can use a simpler layout manager, and pack is one of them.

In the preceding code, we pack the tabControl and ttk.Notebook widgets into the main GUI form, expanding the notebook-tabbed control to fill in all the sides.

We can add a second tab to our control and click between them:

GUI_tabbed_two.py

Now, we have two tabs. Click on Tab 2 to give it the focus:

We would really like to see our windows title; so, to do this, we have to add a widget to one of our tabs. The widget has to be wide enough to expand our GUI dynamically to display our window title: 
GUI_tabbed_two_mighty.py

Now we got our Mighty Python inside Tab1. This  expands our GUI, but the added widgets are not large enough to make the GUI title visible:

After adding a second label plus some spacing around them, we stretch the layout enough to be able to see our GUI title again:

GUI_tabbed_two_mighty_labels.py

We can keep placing all the widgets we have created so far into our newly created tab controls:

GUI_tabbed_all_widgets.py

Now, all the widgets reside inside Tab 1. Let's move some to Tab 2. First, we create a second LabelFrame to be the container of our widgets relocating to Tab 2:

Next, we move the Check and Radiobuttons to Tab 2, by specifying the new parent container, which is a new variable that we name mighty2. Here is an example that we apply to all the controls that relocate to Tab 2:

When we run the code, our GUI now looks different. Tab 1 has fewer widgets than it had before, when it contained all of our previously created widgets:

GUI_tabbed_all_widgets_both_tabs.py

We can now click on Tab 2 and see our relocated widgets:

Clicking the relocated Radiobutton no longer has any effect, so we will change their actions to rename the text property, from the title of the LabelFrame widget, to the name the Radiobuttons display. When we click the Gold Radiobutton, we no longer set the background of the frame to the color gold but here replace the LabelFrame text title instead. Python The Snake now becomes Gold.

Now, selecting any of the RadioButton widgets will change the name of the LabelFrame:

GUI_tabbed_all_widgets_both_tabs_radio.py

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

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