Marcus
Marcus

Reputation: 13

Python time.sleep on line 2 happens before line 1

self.output.clear()
self.output.append("Text that you should see for 2 sec")
time.sleep(2)
self.output.clear()

You are supposed to see the text in a window for 2 seconds then it should clear and continue but the sleep happens before the text shows and it continues to the clear, not showing the text at all. Anyone know who to fix this?

Upvotes: 0

Views: 63

Answers (2)

Marcus
Marcus

Reputation: 13

self.myTimer = QTimer()

self.myTimer.singleShot(2000, lambda: self.output.clear())

Upvotes: 1

George McCollister
George McCollister

Reputation: 256

When you sleep you're probably preventing the rendering from taking place. Try setting the text, then using a timer callback to clear it.

Upvotes: 0

Related Questions