Notebook widget in Tkinter

TkinterServer Side ProgrammingProgramming

Notebook widget is an inbuilt widget of ttk library in tkinter. It enables the user to create Tabs in the window application. Tabs are generally used to separate the workspace and specialize the group of operations in applications at the same time.


In this example, we will create two tabs using Notebook widget and then will add some context to it.

#Import the required library
from tkinter import *
from tkinter import ttk
#Create an instance of tkinter frame
win = Tk()
#Create a Notebook widget
my_notebook= ttk.Notebook(win)
#Create Tabs
tab1= ttk.Frame(my_notebook)
my_notebook.add(tab1, text= "Tab 1")
tab2= ttk.Frame(my_notebook)
my_notebook.add(tab2, text= "Tab2")
#Create a Label in Tabs
Label(tab1, text= "Hello, Howdy?", font= ('Helvetica 20 bold')).pack()
Label(tab2, text= "This is a New Tab Context", font=('Helvetica
20 bold')).pack()


Running the above code will display a window containing two tabs, tab1 and tab2 respectively. Tabs contain some Text Labels in it.

Now, switch to "tab1" and then "tab2" to see the changes between the two tabs.

Published on 16-Apr-2021 10:39:29