其他分享
首页 > 其他分享> > pyqt QSpinBox详细用法

pyqt QSpinBox详细用法

作者:互联网

         QSpinBox可以上下调整值,代码如下:

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class QSpinBoxDemo(QWidget):
    def __init__(self):
        super(QSpinBoxDemo,self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('QSpinBox演示')
        self.resize(300,100)

        layout = QVBoxLayout()
        self.label = QLabel('当前值')
        self.label.setAlignment(Qt.AlignCenter)

        layout.addWidget(self.label)

        self.sbox = QSpinBox()
        self.sbox.setValue(23)      #设置spinbox的值
        self.sbox.setRange(1,70)    #设置范围
        self.sbox.setSingleStep(3)  #设置步长
        layout.addWidget(self.sbox)

        # 链接信号 valueChanged
        self.sbox.valueChanged.connect(self.valueChange)
        self.setLayout(layout)

    def valueChange(self):
        self.label.setText('当前值:' + str(self.sbox.value()))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QSpinBoxDemo()
    main.show()
    sys.exit(app.exec_())

         运行结果如下:

标签:__,layout,sbox,QSpinBox,self,pyqt,用法,label
来源: https://blog.51cto.com/u_12570763/2855317