herr_mueller12
herr_mueller12

Reputation: 21

pyqt start timer only once

Is it possible to start the Qtimer only once if the time is up

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)

Upvotes: 1

Views: 2012

Answers (2)

C.Cheung
C.Cheung

Reputation: 31

Besides the signleShot method as eyllanesc mentioned, you can just stop the timer in self.function.

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

Upvotes: 1

eyllanesc
eyllanesc

Reputation: 244282

To do this you must enable the singleShot property:

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

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

self.timer.start()

Or

QTimer.singleShot(800, self.function)

Upvotes: 3

Related Questions