I'm a tkinter noob.
What would be the preferred way to run a long-running process in the background, separate from my tkinter popup(form?)?
I've read different things about multithreading while using tkinter and can't find a straightforward "do it like this".
To be clear, the behavior I need is, user starts program, tkinter bit pops up saying the process has started. User can dismiss this popup without affecting the rest of the processes. Maybe when the process has finished I can throw up another tkinter popup.
If tkinter is overkill for this, please feel free to suggest a better approach.
Thanks!
解决方案
Joran Beasley has the right answer, but way overcomplicated things. Here's the simple version:
class Worker(threading.Thread):
def run(self):
# long process goes here
w = Worker()
w.start()
tkMessageBox.showinfo("Work Started", "OK started working")
w.join()
tkMessageBox.showinfo("Work Complete", "OK Done")
Edit: here's a working example of it:
import threading
import time
import tkMessageBox
import Tkinter as tk
root = tk.Tk()
root.withdraw()
class Worker(threading.Thread):
def run(self):
# long process goes here
time.sleep(10)
w = Worker()
w.start()
tkMessageBox.showinfo("Work Started", "OK started working")
root.update()
w.join()
tkMessageBox.showinfo("Work Complete", "OK Done")