In this recipe, we will create tabbed widgets to further organize our expanding GUI written in tkinter.
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.
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: