I am a new programmer developing application in wxPython/Python. I am getting inconsistent result from a button event as follows.
def OnButton1Button(self, event):
self.textCtrl9.AppendText(" 1st instance\n")
time.sleep(5)
self.textCtrl9.AppendText(" 2nd instance\n")
It should print 1st instance and then after 5 seconds delay again print 2nd instance. This is working fine in Windows OS but in Linux I am getting both 1st instance & 2nd instance at a time(simultaneously) after a 5 seconds delay of pressing the button.
I am really confused. Could anyone please suggest me some solution.
Thanks in advance.
This should be done using a wx.Timer.
Assuming that your primary goal is to update the GUI after 5 seconds, put the second AppendText in a function and set it to be called with wx.Timer. This way, your GUI will still be responsive during the 5 second delay.
Putting calls to time.sleep() in an event handler in the GUI, and therefore in the main thread, will cause you no end of headaches.
On the other hand, if you really want your GUI to be unresponsive for the 5 seconds, you should do this explicitly, say using Enable(False) with the Window, and again, call Enable(True) using a timer when the 5 seconds are up. This way, it will be indicated to the user that the GUI is inactive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With