Python——GUI可视化
1 import sys 2 from PyQt5.QtCore import * 3 from PyQt5.QtGui import * 4 from PyQt5.QtWidgets import * 5 6 class Form(QDialog): 7 def __init__(self,parent=None): 8 super().__init__(parent) 9 #窗体标题 10 self.setWindowTitle('窗体标题!') 11 #QLabel标签 12 self.aLabel = QLabel(self) 13 self.aLabel.setText('ABCD') 14 #QSpinBox数字框 15 self.mySpinBox = QDoubleSpinBox(self) 16 self.mySpinBox.setValue(100) 17 self.mySpinBox.setRange(1,666) 18 #滑动条 19 self.s = QSlider() 20 #QListWidget选单 21 self.listWidget = QListWidget(self) 22 self.listWidget.addItems(['item1','item2','item3']) 23 #QPushButton按钮 24 self.okButton = QPushButton(self) 25 self.okButton.setText("OK") 26 #可编辑文本框 27 self.lineedit = QLineEdit("Type a string!") 28 #不可编辑文本框 29 self.browser = QTextBrowser() 30 self.browser.append('abcd') 31 #下拉选单 32 self.comboBox = QComboBox(self) 33 itemdata = ['a','b','c'] 34 self.comboBox.addItems(itemdata) 35 36 37 layout = QVBoxLayout() 38 layout.addWidget(self.aLabel) 39 layout.addWidget(self.mySpinBox) 40 layout.addWidget(self.s) 41 layout.addWidget(self.listWidget) 42 layout.addWidget(self.okButton) 43 layout.addWidget(self.lineedit) 44 layout.addWidget(self.browser) 45 layout.addWidget(self.comboBox) 46 self.setLayout(layout) 47 48 #下面这段脚本在PyQt GUI编程中几乎通用的 49 app = QApplication(sys.argv) 50 form = Form() 51 form.show() 52 app.exec_()
输出结果: