pyqt启动计时器只有一次

时间:2020-06-08 16:23:22

标签: python timer pyqt pyqt5

如果时间到了,是否只能启动一次Qtimer

self.timer = QtCore.QTimer()
self.timer.setInterval(10000)
self.timer.start(800)  # start only once, not every 800 milliseconds
self.timer.timeout.connect(self.function)

2 个答案:

答案 0 :(得分:1)

为此,您必须启用singleShot属性:

self.timer = QtCore.QTimer()
self.timer.setSingleShot(True)
self.timer.setInterval(800)

self.timer.timeout.connect(self.function)

self.timer.start()

QTimer.singleShot(800, self.function)

答案 1 :(得分:0)

除了eyllanesc提到的signleShot方法外, 您可以通过self.function停止计时器。

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