定时器事件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_())

 

转载于:https://www.cnblogs.com/ACPIE-liusiqi/p/10610244.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值