How to do it...

Follow these steps to create Tab controls, which in tkinter are called Notebook:

  1. Create a new Python module and name it GUI_tabbed.py.
  2. At the top of the module, import tkinter:
import tkinter as tkfrom tkinter import ttk
  1. Create an instance of the Tk class:
win = tk.Tk()
  1. Add a title via the title attribute:
win.title ("Python GUI")
  1. Create tabControl using the ttk Notebook:
tabControl = ttk.Notebook(win)
  1. Add the tab to tabControl:
tabControl.add(tab1, text-'Tab 1')
  1. Use pack to make the control visible inside the GUI:
tabControl.pack(expand=1, fill="both")

The preceding instructions produce the following code, which can be found in the GUI_tabbed.py file:

  1. Run the preceding code. The following screenshot shows the ...

Get Python GUI Programming Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.