from PyQt5.Qt import *
import sys
class Mywidget(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt5--定时器')
self.resize(500, 500)
self.time_id = self.startTimer(1000)
def timerEvent(self, eve):
self.resize(self.width()+ 100, self.height()+100)
if self.width() == 1000:
self.killTimer(self.time_id)
class Mylabel(QLabel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setText('10')
self.move(200, 195)
self.setStyleSheet('font-size: 43px;')
self.time_id = self.startTimer(1000)
def timerEvent(self, eve):
a = int(self.text())
a = a - 1
self.setText(str(a))
if a == 0 :
self.killTimer(self.time_id)
self.setText('停止')
app = QApplication(sys.argv)
window = Mywidget()
label = Mylabel(window)
window.show()
sys.exit(app.exec_())
自定义定时器~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from PyQt5.Qt import *
class Window(QWidget) :
timer = QTimer()
a = 0
timer1 = QTimer()
b = 100
def __init__(self):
super().__init__()
self.setWindowTitle('空白')
self.resize(500, 500)
self.timer.start(1000)
self.timer1.start(3000)
self.timer.timeout.connect(self.countTime)
self.timer1.timeout.connect(self.countTime1)
self.setup_ui()
def countTime(self):
print(self.a)
self.a += 1
def countTime1(self):
print(self.b)
self.b += 100
def setup_ui(self):
pass
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())