May 2017
Beginner to intermediate
444 pages
11h 31m
English
First, let's move the creation of the thread into its own method and then call this method from the button callback method:
# Running methods in Threads def create_thread(self): self.run_thread = Thread(target=self.method_in_a_thread) self.run_thread.start() # start the thread # Button callback def click_me(self): self.action.configure(text='Hello ' + self.name.get()) self.create_thread()
Clicking the button now results in the create_thread method being called, which, in turn, calls the method_in_a_thread method.
First, we create a thread and target it at a method. Next, we start the thread that runs the targeted method in a new thread:
Read now
Unlock full access