user interface - Python, PySide sleep without stalling the whole program? -
i have piece of code:
self.connect(self.yes_button,signal('clicked()'),self.yes_pressed) self.connect(self.no_button,signal('clicked()'),self.no_pressed) def yes_pressed(self): self.box.append("hello") time.sleep(2) self.box.append("text2")
what when yes button pressed waits 2 seconds first appends both hello , text2(box qtextbrowser() object)how make appending one, wait 2 seconds , append other 1 instead? there simple solution this?
you can this, using pyqt's
qtimer
. more singleshot
setup : qtimer.singleshot (int msec, qobject receiver, slot()slot() member)
qtcore.qtimer.singleshot(1000, lambda: self.box.append("text2")) #1000 milliseconds = 1 second
or can event try implementation:
self.timerscreen = qtimer() self.timerscreen.setinterval(1000) #1000 milliseconds = 1 second self.timerscreen.setsingleshot(true) self.timerscreen.timeout.connect(self.box.append("text2"))
part 2
you can this, not recommend it:
def testsleep(self): self.lineedit.settext('start') qtcore.qtimer.singleshot(10000, lambda: self.box.append("text2")) qtcore.qtimer.singleshot(10000,lambda: self.timerevent) def timerevent(self): qtcore.qtimer.singleshot(10000, lambda: self.box.append("text3"))
you better off doing this:
x = 10000 #or whatever number qtcore.qtimer.singleshot(10000 + x, lambda: self.box.append("text3"))
Comments
Post a Comment