Creating tabbed widgets
In this recipe, we will create tabbed widgets to further organize our expanding GUI written in tkinter.
Getting ready
In order to improve our Python GUI using tabs, we will start at the beginning, using the minimum amount of code necessary. In the following recipes, we will add widgets from previous recipes and place them into this new tabbed layout.
How to do it...
Create a new Python module and place the following code into this module:
import tkinter as tk # imports from tkinter import ttk win = tk.Tk() # Create instance win.title("Python GUI") # Add a title tabControl = ttk.Notebook(win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab tabControl.add(tab1, text='Tab 1') # Add the tab tabControl.pack(expand=1, fill="both") # Pack to make visible win.mainloop() # Start GUI
This creates the following GUI:
![](https://static.packt-cdn.com/products/9781785283758/graphics/B04829_02_06.jpg)
While not amazingly impressive...