0
self.statusBar().showMessage("Product added to database")
self.lineEdit_20.setText("")
self.lineEdit_21.setText("")
self.lineEdit_22.setText("")
time.sleep(3)
self.statusBar().showMessage("")

This is a part of my code in a PyQt5 project. Here is what i expect to happen:

  1. Status bar shows "Product added to database". Line edits show "".
  2. 3 seconds pass.
  3. Status bar shows "".

Yet here is what happens:

  1. Status bar shows "Product added to database".
  2. 3 seconds pass.
  3. Line edits show "". Status bar shows "".

sleep() function doesnt seem to work in correct order. What is the issue here?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 4
    Not sure if it is related to your issue, but you should probably not use `time.sleep()` in a GUI program. If called on the main thread, it will render the GUI unresponsive because it blocks the event loop. – Roland Smith Mar 22 '20 at 19:24
  • `time.sleep()` is unpredictable in a GUI. Why not use QTimer? `QTimer.singleShot(3000, lambda: self.statusBar().showMessage(""))` – alec Mar 22 '20 at 21:05
  • Thanks a lot alec. It solves my problem. – Cagdas Akdemir Mar 23 '20 at 21:58

0 Answers0