Etc. Your do_stuff() function needs to start up the computing thread and then return. Multi-threading is the name given to running multiple activities in a single process - by definition if something is going on "in the background", it's running on a separate thread.
But you don't need to split functions into a different classes to use threads, just be sure that the computing functions don't do anything with the GUI and the main thread doesn't call any of the functions used by the computing thread. EDIT 10/23: Here's a silly example of running threads in a single class - nothing in the language or the threading library requires a different class for each thread. The examples probably use a separate class for processing to illustrate good modular programming.
From tkinter import * import threading class MyApp: def __init__(self, root): self. Root = root self. Timer_evt = threading.Event() cf = Frame(root, borderwidth=1, relief="raised") cf.pack() Button(cf, text="Run", command=self.
Run). Pack(fill=X) Button(cf, text="Pause", command=self. Pause).
Pack(fill=X) Button(cf, text="Kill", command=self. Kill). Pack(fill=X) def process_stuff(self): # processing threads while self.
Go: print("Spam... ") self. Timer_evt.wait() self. Timer_evt.clear() def Run(self): # start another thread self.
Go = 1 threading. Thread(target=self. Process_stuff, name="_proc").start() self.root.
After(0, self. Tick) def Pause(self): self. Go = 0 def Kill(self): # wake threads up so they can die self.
Go = 0 self. Timer_evt.set() def tick(self): if self. Go: self.
Timer_evt.set() # unblock processing threads self.root. After(1000, self. Tick) def main(): root = Tk() root.
Title("ProcessingThread") app = MyApp(root) root.mainloop() main().
Thanks. So how would one use multiple threads without creating a different Class()? All the examples that I've found online use different classes.
– Deusdies Oct 22 at 1:49 @Deusdies: With 500 lines or more in a single class, wouldn't you in fact want to refactor this huge "god-class"? – Hovercraft Full Of Eels Oct 22 at 2:06 @HovercraftFullOfEels: that is the ultimate solution. But I'd rather not to have to do that, if possible.
– Deusdies Oct 22 at 2:23.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.