簡體   English   中英

pyqt 只啟動一次定時器

[英]pyqt start timer only once

如果時間到了,是否可以只啟動一次 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)

為此,您必須啟用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)

除了 eyllanesc 提到的 signleShot 方法外,您還可以在 self.function 中停止計時器。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM