气轻PyQt6 19 微调器(QDoubleSpinBox)与LCD显示器互动
也有把QDoubleSpinBox控件称为数字调节框或计数器的。本程序制作了一个QDoubleSpinBox控件,当数据发生变化时,结果会显示在LCD显示器中。之前的程序中在LCD显示器中直接显示的文字,也可以直接显示数字。
from PyQt6.QtWidgets import *
import sys
class PyQt619(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('气轻PyQt6') # 设置窗口标题
self.resize(290, 50) # 设置窗口大小
self.setStyleSheet('background-color:#40E0D0')
self.lcd = QLCDNumber(self)
self.lcd.setGeometry(10, 0,180, 40) # 设置位置和大小
self.lcd.setDigitCount(10) # 设置显示位数
self.lcd.setStyleSheet('background-color:#7A67EE;color : #32CD32; \
font: bold large /"Times New Roman/";font-size:25px')
self.spin = QDoubleSpinBox(self)
self.spin.setGeometry(190,0,90,40) # 设置位置和大小
self.spin.setRange(35,40)
self.spin.setSingleStep(0.1)
self.spin.setDecimals(1)
self.spin.setValue(36.6)
self.spin.setStyleSheet('background-color:#7A67EE;color : #32CD32; \
font: bold large /"Times New Roman/";font-size:25px')
self.lcd.display(self.spin.value())
self.spin.valueChanged.connect(lambda :self.lcd.display(self.spin.value()))
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = PyQt619()
sys.exit(app.exec())
执行结果
