import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class Form(QDialog):
def __init__(self,parent=None):
super().__init__(parent)
#窗体标题
self.setWindowTitle('窗体标题!')
#QLabel标签
self.aLabel = QLabel(self)
self.aLabel.setText('ABCD')
#QSpinBox数字框
self.mySpinBox = QDoubleSpinBox(self)
self.mySpinBox.setValue(100)
self.mySpinBox.setRange(1,666)
#滑动条
self.s = QSlider()
#QListWidget选单
self.listWidget = QListWidget(self)
self.listWidget.addItems(['item1','item2','item3'])
#QPushButton按钮
self.okButton = QPushButton(self)
self.okButton.setText("OK")
#可编辑文本框
self.lineedit = QLineEdit("Type a string!")
#不可编辑文本框
self.browser = QTextBrowser()
self.browser.append('abcd')
#下拉选单
self.comboBox = QComboBox(self)
itemdata = ['a','b','c']
self.comboBox.addItems(itemdata)
layout = QVBoxLayout()
layout.addWidget(self.aLabel)
layout.addWidget(self.mySpinBox)
layout.addWidget(self.s)
layout.addWidget(self.listWidget)
layout.addWidget(self.okButton)
layout.addWidget(self.lineedit)
layout.addWidget(self.browser)
layout.addWidget(self.comboBox)
self.setLayout(layout)
#下面这段脚本在PyQt GUI编程中几乎通用的
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
输出结果:
手机扫一扫
移动阅读更方便
你可能感兴趣的文章