我是一个 tkinter 菜鸟。
在后台运行长时间运行的进程(与我的 tkinter 弹出窗口(表单?)分开)的首选方式是什么?
我在使用 tkinter 时阅读了有关多线程的不同内容,但找不到简单的“这样做”。
需要明确的是,我需要的行为是,用户启动程序,tkinter 位弹出,表示进程已启动。用户可以关闭此弹出窗口,而不会影响其余进程。也许当该过程完成后,我可以弹出另一个 tkinter 弹出窗口。
如果 tkinter 对此太过分了,请随意提出更好的方法。
Thanks!
乔兰·比斯利有权利answer,但事情过于复杂。
这是简单的版本:
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")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)