mytimerevent.py
from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * import sys class MyWidget(QWidget): def __init__(self, parent = None): super().__init__(parent) self.setWindowTitle(self.tr(‘计时器‘)) self.resize(640,480) self.id1 = self.startTimer(1000) self.id2 = self.startTimer(1500) self.id3 = self.startTimer(2200) self.timer = QTimer(self) self.timer.timeout.connect(self.updateTime) self.timer.start(1000) #self.label = QLabel(self) #self.label.resize(100,100) timefont = QFont() timefont.setFamily(self.tr(‘黑体‘)) timefont.setBold(True) timefont.setPointSize(20) self.lcd = QLCDNumber(self) #self.lcd.setDigitCount(8) #self.label.clear() self.lcd.setFont(timefont) self.lcd.resize(100,100) self.lcd.move(200,200) #self.lcd1 = QLCDNumber(self) def timerEvent(self, event): if event.timerId() == self.id1: print(self.tr(‘第一个计时器时间到‘)) elif event.timerId() == self.id2: print(self.tr(‘第二个计时器时间到‘)) else: print(self.tr(‘第三个计时器时间到‘)) def updateTime(self): currentTime = QTime.currentTime() if currentTime.second()%2 == 0: timeStr = currentTime.toString(‘hh:mm‘) else: timeStr = currentTime.toString(‘hh mm‘) self.lcd.display(timeStr) if __name__ == ‘__main__‘: app = QApplication(sys.argv) widget = MyWidget() widget.show() print(widget.children()) sys.exit(app.exec_())
定时器事件QTimerEvent,开启多个定时器,利用定时器和QLCDnumber实现电子表
原文:https://www.cnblogs.com/ACPIE-liusiqi/p/10610244.html