PyQt5 - QTabWidget

PyQt5 - QTabWidget

QTabWidget is a widget provided by PyQt5 that allows you to organize multiple widgets or groups of widgets into a tabbed interface. Each tab contains its own widget, making it useful for organizing related content into separate tabs.

Here's a basic introduction to using QTabWidget in PyQt5:

  1. Creating a QTabWidget:

    tabWidget = QTabWidget() 
  2. Adding Tabs:

    Use the addTab method to add new tabs to the QTabWidget.

    tabWidget.addTab(tab1_widget, "Tab 1") tabWidget.addTab(tab2_widget, "Tab 2") 

    Here, tab1_widget and tab2_widget are the widgets that will be displayed when the respective tab is active.

  3. Example:

    Here's a simple example demonstrating the usage of QTabWidget:

    import sys from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QTabWidget app = QApplication(sys.argv) # Main window window = QWidget() window.setWindowTitle("QTabWidget Example") layout = QVBoxLayout() # Create a tab widget tabWidget = QTabWidget() # Create first tab tab1 = QWidget() tab1_layout = QVBoxLayout() tab1_label = QLabel("This is Tab 1 content") tab1_layout.addWidget(tab1_label) tab1.setLayout(tab1_layout) tabWidget.addTab(tab1, "Tab 1") # Create second tab tab2 = QWidget() tab2_layout = QVBoxLayout() tab2_label = QLabel("This is Tab 2 content") tab2_layout.addWidget(tab2_label) tab2.setLayout(tab2_layout) tabWidget.addTab(tab2, "Tab 2") # Add the tab widget to the main window layout layout.addWidget(tabWidget) window.setLayout(layout) window.show() sys.exit(app.exec_()) 

In this example, we've created a QTabWidget with two tabs, each containing a label. This is a simple demonstration, but you can populate each tab with any widgets or layouts you require.


More Tags

ggplot2 intersection-observer phpspreadsheet transactional apex extension-methods entity-framework-5 cassandra-3.0 dimensions qt-designer

More Programming Guides

Other Guides

More Programming Examples