Exploring Tab Widgets in PySide6 (Part 4)

 · 4 mins read

In this tutorial, we’ll delve into the usage of tab widgets in PySide6 to create a multi-tabbed graphical user interface (GUI). Tab widgets allow us to organize content into multiple tabs, making it easier for users to navigate between different sections of an application. We’ll build a simple example application to demonstrate how to create and customize tab widgets in PySide6.


Before we begin, ensure you have Python and PySide6 installed on your system. You can install PySide6 using pip:

pip install PySide6

Designing the GUI

Our GUI will consist of a main window with a tab widget containing multiple tabs, each with its own content.


import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QTabWidget, QWidget, QLabel

class TabWidgetApp(QMainWindow):
    def __init__(self):
        self.setWindowTitle('Tab Widget Demo')
        self.setGeometry(100, 100, 400, 300)

        self.central_widget = QWidget()

        self.layout = QVBoxLayout(self.central_widget)

        self.tab_widget = QTabWidget()
        self.tab1 = QWidget()
        self.tab2 = QWidget()
        self.tab3 = QWidget()

        self.tab_widget.addTab(self.tab1, "Tab 1")
        self.tab_widget.addTab(self.tab2, "Tab 2")
        self.tab_widget.addTab(self.tab3, "Tab 3")



    def initTab1(self):
        layout = QVBoxLayout(self.tab1)
        label = QLabel("Content of Tab 1")

    def initTab2(self):
        layout = QVBoxLayout(self.tab2)
        label = QLabel("Content of Tab 2")

    def initTab3(self):
        layout = QVBoxLayout(self.tab3)
        label = QLabel("Content of Tab 3")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    tabWidgetApp = TabWidgetApp()

Understanding the Code

  • We create a class TabWidgetApp inheriting from QMainWindow.
  • In the initUI method, we set up the main window and create a central widget.
  • We create a QTabWidget and add three tabs to it.
  • Each tab is represented by a QWidget.
  • We use the addTab method to add tabs to the tab widget.
  • We initialize the content of each tab using separate methods (initTab1, initTab2, initTab3).

Running the Application

Save the code to a file (e.g., tab_widget_app.py) and execute it using Python:

python tab_widget_app.py

You should see the GUI window with the tab widget containing three tabs, each displaying its own content.


In this tutorial, we explored how to create and customize tab widgets in PySide6. Tab widgets are a convenient way to organize content into multiple tabs, making it easier for users to navigate through different sections of an application. You can further enhance this application by adding more tabs, incorporating different widgets and layouts within each tab, or styling the GUI components to match your design preferences. Experiment with the code and explore the possibilities of PySide6 to create even more versatile and user-friendly GUI applications!