pyqt启动计时器仅一次

问题描述 投票:1回答:2

如果时间到了,是否仅可以启动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)
python timer pyqt pyqt5
2个回答
1
投票

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

singleShot

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

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

self.timer.start()

0
投票

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

QTimer.singleShot(800, self.function)
© www.soinside.com 2019 - 2024. All rights reserved.