长时间执行后台任务,UI会处于无响应状态。在子线程里更新UI状态,听说是不允许的。在哪个线程里调用了tk.mainloop(),就只能在哪个线程里更新UI。
下例演示了如何更新。
import Tkinter as tk
from ttk import *
import time
import Queue, threading
class MainWindow:
def __init__(self):
self.root = tk.Tk()
self.root.title('Demo')
def show(self):
self.progress = tk.IntVar()
self.progress_max = 100
self.progressbar = Progressbar(self.root, mode='determinate', orient=tk.HORIZONTAL, variable=self.progress, maximum=self.progress_max)
self.progressbar.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
self.progress.set(0)
btn = tk.Button(self.root, text='start', command=self.start)
btn.pack(fill=tk.BOTH, expand=True, padx=15, pady=5)
self.btn = btn
self.root.mainloop()
def star