QDoubleSpinBox浮点型数字调节框
样式:
1 import sys 2 from PyQt5.QtWidgets import QApplication, QWidget, QDoubleSpinBox 3 4 class Demo(QWidget): 5 def __init__(self): 6 super(Demo, self).__init__() 7 self.double_spinbox = QDoubleSpinBox(self) # 实例化浮点型数字调节框 8 self.double_spinbox.setDecimals(2) #设置小数位数也就是精度,默认2位 9 self.double_spinbox.setRange(-99.99, 99.99) #设置范围 10 self.double_spinbox.setSingleStep(0.01) # 设置步长,即每次点击递增或递减多少值 11 self.double_spinbox.setValue(66.00) # 设置显示值 12 self.double_spinbox.valueChanged.connect(self.v) # 值发生变化时发出信号 13 self.double_spinbox.setMinimum(65.00) # 设置最小值 14 self.double_spinbox.setMaximum(80) # 设置最大值 15 16 17 def v(self): 18 print(self.double_spinbox.value()) #返回当前值 19 20 if __name__ == '__main__': 21 app = QApplication(sys.argv) 22 demo = Demo() 23 demo.show() 24 sys.exit(app.exec_())