【发布时间】:2014-11-18 01:17:28
【问题描述】:
这可能以前被问过,但我找不到我要找的东西。我有从主 UI 线程(TKinter)启动的后台线程,我希望它将状态更新发送到 UI。我很欣赏一些代码或伪代码或链接,它们显示了如何在 python 中完成此操作。
伪代码: //test.py
def __init__(self, parent):
#Button
self.submit_button = Button(self,
text="launch_tasks",
command=self.launch_tasks).pack()
#label
self.label = Label(master, text="Hello, world!")
self.label.pack()
def launch_tasks(self)
t = Thread(target=self.process_tasks)
t.start()
def process_tasks(self):
cnt = getJobs(self);
self.label = cnt # I like to update label here
for(job in jobs):
process(job)
self.label = 'processing' + job # I like to update label
...
【问题讨论】:
标签: multithreading tkinter python-multithreading