Adding a loop into our button callback method with some sleep time results in our GUI becoming unresponsive and, when we try to close the GUI, things get even worse.
- Open GUI_multiple_threads.py and save it as GUI_multiple_threads_sleep_freeze.py.
- Make the following changes to the code:
# Button callbackdef click_me(self): self.action.configure(text='Hello ' + self.name.get() + ' ' + self.number_chosen.get()) # Non-threaded code with sleep freezes the GUI for idx in range(10): sleep(5) self.scrol.insert(tk.INSERT, str(idx) + 'n')
- Running the preceding code results in the following screenshot:
- Let's move the creation ...