标签:import spinbox widget value 范围 变化 最大值 elf tran
样式:
1 import sys 2 from PyQt5.QtWidgets import QApplication, QWidget, QSpinBox, QDoubleSpinBox, QHBoxLayout 3 4 5 class Demo(QWidget): 6 def __init__(self): 7 super(Demo, self).__init__() 8 self.spinbox = QSpinBox(self) #实例化数字调节框 9 self.spinbox.setRange(-99, 99) # 设置范围。默认范围为0-99 10 self.spinbox.setSingleStep(1) # 设置步长,即每次点击递增或递减多少值 11 self.spinbox.setValue(66) # 设置显示值 12 self.spinbox.valueChanged.connect(self.value_change_func) # 值发生变化时发出信号 13 14 self.double_spinbox = QDoubleSpinBox(self) # 实例化浮点型数字调节框 15 self.double_spinbox.setRange(-99.99, 99.99) #设置范围 16 self.double_spinbox.setSingleStep(0.01) # 设置步长,即每次点击递增或递减多少值 17 self.double_spinbox.setValue(66.66) # 设置显示值 18 19 self.h_layout = QHBoxLayout() 20 self.h_layout.addWidget(self.spinbox) 21 self.h_layout.addWidget(self.double_spinbox) 22 self.setLayout(self.h_layout) 23 24 def value_change_func(self): 25 decimal_part = self.double_spinbox.value() - int(self.double_spinbox.value()) 26 self.double_spinbox.setValue(self.spinbox.value() + decimal_part) 27 28 29 if __name__ == ‘__main__‘: 30 app = QApplication(sys.argv) 31 demo = Demo() 32 demo.show() 33 sys.exit(app.exec_())
1 import sys 2 from PyQt5.QtWidgets import QApplication, QWidget, QSpinBox 3 4 5 class Demo(QWidget): 6 def __init__(self): 7 super(Demo, self).__init__() 8 self.spinbox = QSpinBox(self) #实例化数字调节框 9 self.spinbox.setRange(-99, 99) # 设置范围。默认范围为0-99 10 self.spinbox.setSingleStep(1) # 设置步长,即每次点击递增或递减多少值,默认是1 11 self.spinbox.setValue(66) # 设置显示值 12 self.spinbox.valueChanged.connect(self.v) # 值发生变化时发出信号 13 self.spinbox.setMinimum(50) #设置最小值 14 self.spinbox.setMaximum(80) #设置最大值 15 16 17 def v(self): 18 print(self.spinbox.value()) #返回当前值 19 20 21 if __name__ == ‘__main__‘: 22 app = QApplication(sys.argv) 23 demo = Demo() 24 demo.show() 25 sys.exit(app.exec_())
标签:import spinbox widget value 范围 变化 最大值 elf tran
原文地址:https://www.cnblogs.com/liming19680104/p/10358708.html