1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import sys from PyQt4.QtCore import * from PyQt4.QtGui import *
class window(QTabWidget): def __init__(self, parent=None): super(window, self).__init__(parent) self.init()
def init(self): self.tab1 = QWidget() self.tab2 = QWidget() self.tab3 = QWidget()
self.addTab(self.tab1, "Tab 1") self.addTab(self.tab2, "Tab 2") self.addTab(self.tab3, "Tab 3") self.tab1Window() self.tab2Window() self.tab3Window() self.setWindowTitle("tab demo")
def tab1Window(self): layout = QFormLayout() layout.addRow("Name", QLineEdit()) layout.addRow("Address", QLineEdit()) self.setTabText(0, "Contact Details") self.tab1.setLayout(layout)
def tab2Window(self): layout = QFormLayout() sex = QHBoxLayout() sex.addWidget(QRadioButton("Male")) sex.addWidget(QRadioButton("Female")) layout.addRow(QLabel("Sex"), sex) layout.addRow("Date of Birth", QLineEdit()) self.setTabText(1, "Personal Details") self.tab2.setLayout(layout)
def tab3Window(self): layout = QHBoxLayout() layout.addWidget(QLabel("subjects")) layout.addWidget(QCheckBox("Physics")) layout.addWidget(QCheckBox("Maths")) self.setTabText(2, "Education Details") self.tab3.setLayout(layout)
def main(): app = QApplication(sys.argv) ex = window() ex.show() sys.exit(app.exec_())
if __name__ == '__main__': main()
|