zoukankan      html  css  js  c++  java
  • 定时器事件QTimerEvent,开启多个定时器,利用定时器和QLCDnumber实现电子表

    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_())
  • 相关阅读:
    C#设计模式(2)——简单工厂模式
    C#设计模式(1)——单例模式
    静态变量与静态方法
    在服务器操作系统上使用TeamViewer
    51 nod 1439 互质对(Moblus容斥)
    51 nod 1495 中国好区间
    51nod 1103 N的倍数(抽屉原理)
    51 nod 1427 文明 (并查集 + 树的直径)
    51nod 1486 大大走格子(容斥原理)
    hihocoder 1388 fft循环矩阵
  • 原文地址:https://www.cnblogs.com/ACPIE-liusiqi/p/10610244.html
Copyright © 2011-2022 走看看