I am working on a project that follows the basic structure: a sequencer class instantiates a GUI class that provides functionality to update/modify content on the GUI (change background image, update text fields, etc.). In the sequencer class, I want to kick off some method run_test
that performs some actions (including some time.sleep()
commands, and also updates the GUI to show that the test is running. Obviously, the GUI mainloop freezes when this occurs and the GUI does not update.
What's the right solution here? How do I kick off the run_test in another thread so that the GUI can update?
class TestSequencer():
def __init__(self):
self._gui = TestGUI(sequencer=self)
self._gui.run_gui()
def start_sequencer(self):
self._gui.update_background_image()
self.run_test()
def run_test(self):
time.sleep(5)
The result is such that the code sleeps for 5 seconds, after which the GUI updates the background image. I want it to occur immediately, and potentially on the fly as various things occur during run_test (e.g. depending on pass/fail of run_test, show different things on the GUI).
How do I accomplish this?!