Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

Creating Tabbed Widget With Python For GUI Application

2 min read

In this tutorial, we will learn how to create a tabbed widget interface by using Python GUI and Tkinter package.

The Tkinter module (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and Tkinter are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)

Tkinter package is shipped with Python as a standard package, so we don’t need to install anything to use it.

Creating Tabbed Widget With Python

import tkinter as tk
from tkinter import ttk

# intializing the window

window = tk.Tk()window.title("TABS")
# configuring size of the window
window.geometry('350x200')

#Create Tab Control

TAB_CONTROL = ttk.Notebook(window)
#Tab1TAB1 = ttk.Frame(TAB_CONTROL)
TAB_CONTROL.add(TAB1, text='Tab 1')

#Tab2TAB2 = ttk.Frame(TAB_CONTROL)
TAB_CONTROL.add(TAB2, text='Tab 2')
TAB_CONTROL.pack(expand=1, fill="both")
#Tab Name 
Labelsttk.Label(TAB1, text="This is Tab 1").grid(column=0, row=0, padx=10, pady=10)
ttk.Label(TAB2, text="This is Tab 2").grid(column=0, row=0, padx=10, pady=10)
#Calling Main()
window.mainloop()

Save this code and run the file you should see a tabular window as below on your screen.

Creating tabbed widgets using python

Explanation

First, we are importing the tkinter modules. Next, in the object window we are initializing the widget.

Then using the geometry('350x200') method we have assigned a default value for the size of the widget. This line sets the window width to 350 pixels and the height to 200 pixels.

Later we have a tab control, the Notebook method manages collections of windows and displays one at a time, basically used for creating tabular widgets.

Below that we have declared two tabs, and assigned some text and padding for styling. At the end we have window.mainloop() this function calls the endless loop of the window, so the window will wait for any user interaction till we close it.


PYTHON

Latest Articles

Latest from djangocentral

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read