PyQt5定时器

使用QTimer做了一个计时工具
PyQt5定时器_第1张图片

import sys
from PyQt5.QtWidgets import QWidget,QApplication
from PyQt5.QtCore import QTime,QTimer
from Timer import Ui_Form

class TimerWgt(QWidget):

    def __init__(self,parent = None):
        super().__init__(parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.__second = 0
        self.__minute = 0
        self.__hour = 0

        self.timer = QTimer()
        self.timer.timeout.connect(self.timeout)

        self.ui.pushButtonOK.clicked.connect(self.btnOK)
        self.ui.pushButtonStop.clicked.connect(self.btnStop)

    def timeout(self):
        self.__second = self.__second + 1
        if(self.__second > 59):
            self.__minute += 1
            self.__second = 0
            if(self.__minute > 59):
                self.__hour += 1
                self.__minute = 0

        self.ui.lcdNumberSecond.display(self.__second)
        self.ui.lcdNumberMinute.display(self.__minute)
        self.ui.lcdNumberHour.display(self.__hour)

    def btnOK(self):
        self.__interval = int(self.ui.lineEdit.text())
        self.timer.start(self.__interval)

    def btnStop(self):
        self.timer.stop()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    timerWgt = TimerWgt()
    timerWgt.show()
    sys.exit(app.exec_())

aaa

你可能感兴趣的:(PyQt)