pyside6 tab widget
时间: 2023-09-22 17:11:20 浏览: 112
tab.py脚本
PySide6 is a Python module that provides bindings for the Qt framework. The Qt framework is a popular cross-platform application development framework that allows developers to create applications that can run on multiple operating systems.
The QTabWidget class in PySide6 provides a container widget for displaying multiple pages of content, each represented by a tab. Here is an example of how to create a simple tab widget in PySide6:
```
import sys
from PySide6.QtWidgets import QApplication, QTabWidget, QWidget, QVBoxLayout, QLabel
class MyTabWidget(QTabWidget):
def __init__(self):
super().__init__()
# Create two tabs
self.tab1 = QWidget()
self.tab2 = QWidget()
self.addTab(self.tab1, "Tab 1")
self.addTab(self.tab2, "Tab 2")
# Add some content to the first tab
layout1 = QVBoxLayout()
self.label1 = QLabel("This is the first tab!")
layout1.addWidget(self.label1)
self.tab1.setLayout(layout1)
# Add some content to the second tab
layout2 = QVBoxLayout()
self.label2 = QLabel("This is the second tab!")
layout2.addWidget(self.label2)
self.tab2.setLayout(layout2)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyTabWidget()
widget.show()
sys.exit(app.exec_())
```
In this example, we create a custom class called `MyTabWidget` that inherits from `QTabWidget`. In the constructor, we create two tabs and add them to the tab widget using the `addTab` method. We then add some content to each tab using `QVBoxLayout` layouts and `QLabel` widgets.
Finally, we create an instance of `MyTabWidget` and show it using `show()`. We also start the event loop using `app.exec_()` to keep the application running.
阅读全文