python之關於QTimer.singleShot()的應用記錄
阿新 • • 發佈:2018-12-10
# -*- coding: utf-8 -*- ''' 關於QTimer.singleShot()的應用記錄 ''' import time import numpy as np import matplotlib.pyplot as plt import winsound import sys import sklearn from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel from PyQt5.QtCore import QTimer, Qt num = 0 class my_num(QWidget): def __init__(self): super(my_num, self).__init__() self.InitUi() def InitUi(self): self.resize(600, 400) self.setWindowTitle('demo') self.btn_1 = QPushButton('累加', self) self.btn_1.setGeometry(60, 120, 150, 100) self.btn_1.clicked.connect(self.m_add) self.label = QLabel("<h1>0</h1>", self) # 設定Label的字型大小,通過html的格式設定 self.label.setGeometry(300, 120, 300, 100) self.label.setAlignment(Qt.AlignCenter) self.mt = QTimer(self) def my_timer(self): if self.btn_1.clicked: self.mt.singleShot(500, self.m_add) def m_add(self): global num num += 1 print('num = {}'.format(num)) self.label.setText("<h1>{}</h1>".format(num)) self.my_timer() if __name__ == '__main__': app = QApplication(sys.argv) w = my_num() w.show() sys.exit(app.exec_())
我曾經跨過山和大海,也穿過人山人海,我曾經擁有著的一切,轉眼都飄散如煙,我曾經失落失望失掉所有方向,直到看見平凡才是唯一的答案。 ——韓寒《平凡之路》