O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Notebook widget

The Notebook widget is only available in ttk, rather than the regular Tkinter. The widget is used to create a tabbed interface for displaying multiple Frame widgets in one window. A small example will demonstrate this nicely:

import tkinter as tkimport tkinter.ttk as ttkwin = tk.Tk()win.geometry("400x400")n = ttk.Notebook(win)frame_one = ttk.Frame(n)frame_two = ttk.Frame(n)label_one = ttk.Label(frame_one, text="We are in frame 1")label_two = ttk.Label(frame_two, text="We are in frame 2")

We create an instance of the Notebook widget, then two Frame widgets to act as tabs.

Inside these two Frame widgets will be a Label widget which informs us which Frame we are seeing.

We now need to add these Frame widgets to our Notebook ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required