from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import sys class StackedExample(QTabWidget): """ 堆栈窗口控件:QStackedWidget """ def __init__(self): super(StackedExample, self).__init__() self.setGeometry(300, 50, 600, 400) # QWidget, ax: int, ay: int, aw: int, ah: int self.setWindowTitle('堆栈窗口控件:QStackedWidget') # self.resize(600, 400) self.list = QListWidget() self.list.insertItem(0, '联系方式') self.list.insertItem(1, '个人信息') self.list.insertItem(2, '教育程度') self.stack1 = QWidget() self.stack2 = QWidget() self.stack3 = QWidget() self.tab1UI() self.tab2UI() self.tab3UI() # 创建堆栈窗口控件的对象 self.stack = QStackedWidget() self.stack.addWidget(self.stack1) self.stack.addWidget(self.stack2) self.stack.addWidget(self.stack3) hbox = QHBoxLayout() hbox.addWidget(self.list) hbox.addWidget(self.stack) self.setLayout(hbox) # 当前行变化 self.list.currentRowChanged.connect(self.display) def tab1UI(self): layout = QFormLayout() layout.addRow('姓名', QLineEdit()) layout.addRow('地址', QLineEdit()) self.setTabText(0, '联系方式') self.stack1.setLayout(layout) def tab2UI(self): layout = QFormLayout() sex = QHBoxLayout() # 单选按钮控件 QRadioButton sex.addWidget(QRadioButton('男')) sex.addWidget(QRadioButton('女')) layout.addRow(QLabel('性别'), sex) layout.addRow('生日', QLineEdit()) self.setTabText(1, '个人详细信息') self.stack2.setLayout(layout) def tab3UI(self): layout = QHBoxLayout() layout.addWidget(QLabel('科目')) # QCheckBox 复选框控件还记得吗 layout.addWidget(QCheckBox('物理')) layout.addWidget(QCheckBox('高数')) self.setTabText(2, '科目') self.stack3.setLayout(layout) def display(self, index): self.stack.setCurrentIndex(index) if __name__ == '__main__': app = QApplication(sys.argv) main = StackedExample() print(main.__doc__) main.show() sys.exit(app.exec_())结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)