Joran比斯利有正確的答案,但過於複雜的方式事情。下面是簡單的版本:
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")
編輯:這裏是它的一個工作示例:
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")
這真棒,正是我想要的,謝謝! – lsp