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