import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class QSpinBoxDemo(QWidget):
def __init__(self):
super(QSpinBoxDemo, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('QSpinBox演示')
self.resize(300, 100)
self.lable=QLabel('当前值:')
self.lable.setAlignment(Qt.AlignCenter)
self.sb = QSpinBox()
self.sb.setValue(18)
self.sb.setRange(10, 38)
self.sb.setSingleStep(3)
self.sb.valueChanged.connect(self.valueChange)
layout = QVBoxLayout()
layout.addWidget(self.lable)
layout.addWidget(self.sb)
self.setLayout(layout)
def valueChange(self):
self.lable.setText('当前值:' + str(self.sb.value()))
if __name__ == '__main__':
app = QApplication(sys.argv)
win = QSpinBoxDemo()
win.show()
sys.exit(app.exec_())
42 计数器控件(QSpinBox)
最新推荐文章于 2023-08-10 12:58:05 发布