• 定时器事件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_())
  • 相关阅读:
    二进制流 最后一段数据是最后一次读取的byte数组没填满造成的
    java中的匿名内部类总结
    决策树构建算法之—C4.5
    Segment公司--整合数据进行分析
    UBuntu安裝使用PIP
    undefined reference to “boost” in Qt—Ubuntu
    Ubuntu14.04引导菜单修复
    ubuntu16.04下编译安装OpenCV
    PCL:Ubuntu下安装配置PCL
    Ubuntu安装配置Python.pyDev
  • 原文地址:https://www.cnblogs.com/ACPIE-liusiqi/p/10610244.html
Copyright © 2020-2023  润新知