EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Tkinter Tutorial Tkinter Notebook
Secondary Sidebar
Tkinter Tutorial
  • Tkinter
    • Python Tkinter
    • Tkinter Widgets
    • Tkinter background image
    • Tkinter button color
    • Tkinter place
    • Python Tkinter Button
    • Python Tkinter Canvas
    • Tkinter Frame
    • Tkinter LabelFrame
    • Python Tkinter Label
    • Tkinter Text
    • Tkinter Scrollbar
    • Tkinter Listbox
    • Tkinter Spinbox
    • Tkinter Checkbutton
    • Tkinter Menu
    • Tkinter Menubutton
    • Tkinter OptionMenu
    • Tkinter Messagebox
    • Tkinter Grid
    • Tkinter Pack
    • Tkinter Scale
    • Tkinter Table
    • Python Tkinter Entry
    • Tkinter after
    • Tkinter Colors
    • Tkinter Font
    • Tkinter PhotoImage
    • Tkinter TreeView
    • Tkinter Notebook
    • Tkinter Combobox
    • Tkinter Bind
    • Tkinter Icon
    • Tkinter Window Size
    • Tkinter Color Chart
    • Tkinter Slider
    • Tkinter Calculator
    • Tkinter geometry
    • Tkinter image
    • Tkinter input box
    • Tkinter mainloop

Tkinter Notebook

By Abhilasha ChouguleAbhilasha Chougule

Tkinter Notebook

Introduction to Tkinter Notebook

In Python Tkinter notebook is defined as tabs for controlling tabs that are provided by ttk library and such a tabbed widget is used for allowing to navigate from one page to another which can be done using the index tab. In general, this notebook widget is defined as an area or tab which allows users to select pages of content that are required by the user, and this is done by pressing or clicking on tabs that are created at the top area of the parent notebook and after setting up such parent notebook we can easily add the tabs and each click on these tabs the notebook widget will display the associated child pane.

Working of Tkinter Notebook with Example

In this article, we are discussing the notebook widget of Tkinter in Python. This widget acts as tabs or we can say tabbed notebook. This widget is obtained from the ttk library which is useful in managing a set of windows and it will start displaying one window at each time. Therefore we can say that users can select the slave window related to the tab to change the present displaying window. This notebook widget uses few methods to add and remove tabs such as add() for adding tabs and some other methods for temporarily hide the tabs or delete the tabs. This widget also provides a collection of options for each tab which are generally used for controlling the appearances and the behavior of the tabs within the widgets, where these options are classified as standard options, widget specific options, and tab options and the notebook widget uses tab id to refer to another tab within the widgets to switch from one page to another.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

In the below section let us see the syntax of the Tkinter notebook which can be declared as the command form as wells as method form.

Syntax:

ttk.notebook(root, options)

In the above syntax, we can see that the notebook widget is obtained from ttk module and it has 2 parameters the root parameter which specifies the parent or master window, and the second parameter options are classified into as standard options, tab options, widget options such as class, cursor, weight, padding, state, text, image, etc.

There are a few methods provided by the notebook widget such as add() for adding tabs, cget() can obtain the current value of the configuration option, hide() to hide the tabs, index() to obtain the index in the numeric value of the specified tab, etc.

In Python, Tkinter is a module for developing GUI-based apps, whereas the notebook widget is obtained from the ttk module which is considered as an extension of the Tkinter module or we can say the improvement of this Tkinter module. So when we are using this notebook widget we have to import ttk module which is used for creating tabs in the windows and can display one window at a time and the child window is associated with each of the tabs created and these tabs are usually used whenever the user wants to display some message of the widow.

Let us see a simple example of creating tabs in the window using a notebook widget of ttk module.

Example

Code:

from Tkinter import *
import Tkinter as tk					 
import ttk
import tkMessageBox
master = tk.Tk()
master.geometry('500x200') 
def func():
    tkMessageBox.showinfo( "Hello Educba", "Click on the tabs to view the content")    
b1 = Button( master, text='Click me for next step', background = 'Red', fg = '#000000', command = func)
b1.pack()
tc = ttk.Notebook(master) 

t1 = ttk.Frame(tc) 
t2 = ttk.Frame(tc) 
tc.add(t1, text ='Notebook tab1') 
tc.add(t2, text ='Notebook tab2') 
tc.pack(expand = 1, fill ="both") 
ttk.Label(t1, 
		text ="Hello Educba Technology Institute").grid(column = 3, 
							row = 3)				     
ttk.Label(t2, 
		text ="Notebook widget demonstration").grid(column = 3, 
									row = 3) 
master.mainloop()

Output:

tkinter notebook 1-1

tkinter notebook 1-2

In the above article, we can see we are first importing the modules Tkinter for developing GUI, ttk module for using notebook widget for creation of tabs within the parent window, tkmessagebox module for displaying any message on the pop-up dialogue box, and in the above example it will pop up the message when we click the button widget on the window it will display as “click on the tabs t view the content” so that the user can go for switching between windows one at a time using these created tabs using notebook widget. In this program then we have passed the parent window to the notebook() so that we can have control over the tabs to switch and to display the content as the tabs are created we need separate frames to do so. Therefore for each tab, we have used the frame method and have passed the tab names to this frame() method. Then by using the add() function we are adding the name to each tab by using text argument and we have named the tabs as t1 as “Notebook Tab1”, t2 as “Notebook tab2”. Then to display the content by clicking each tab we have for tab “Notebook tab1” we are displaying the content as “Hello Educba Technology Institute” and for the tab “Notebook tab2” we are displaying “Notebook widget demonstration” and this content is displayed using label() function where it also takes text argument for the content and where the content should be displayed can be used by grid() function and here we have to display the message on column 3 and row 3 for both tabs. And the output of the entire program can be seen in the above screenshots.

Conclusion

In this article, we conclude in the Python ttk module is used as an extension or improvement of the Tkinter module. In ttk module, it provides some new widgets and in this article, we have discussed one such widget called notebook widget which is used for the creation of tabs so that using notebook widget we can toggle between the windows but one at a time and also display the content of the window. In this article, we have seen the syntax of the notebook widget and the options such as a cursor, weight, height, etc it uses and few methods like add(), Label, etc. In this article, we also saw one simple example which has two tabs in the same parent window but when tabs are clicked we are switching from one window to another one at a time.

Recommended Articles

This is a guide to Tkinter Notebook. Here we discuss the Introduction and working of Tkinter Notebook along with an example and code implementation. You may also have a look at the following articles to learn more –

  1. Tkinter LabelFrame
  2. Tkinter Combobox
  3. Tkinter after
  4. Tkinter Colors
Popular Course in this category
Tkinter Course (1 Course, 1 Project)
  1 Online Courses |  1 Hands-on Projects |  6+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more