我不太明白您要完成什么,但仅根据问题的标题,我猜您想要某种弹出进度窗口,该窗口会在进度完成时自行破坏。
这是一个人为的示例,它显示一个在进度超过 100% 时自毁的窗口。它不是很防弹,但它表明可以创建一个自毁的窗口。
import Tkinter as tk
class App(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
go_button = tk.Button(text="Go!", command=self.go)
go_button.pack()
def go(self):
self.dialog = ProgressWindow(self)
self.do_real_work(0)
def do_real_work(self, count):
# simulate doing work; update the status window periodically
self.dialog.set(count)
self.after(500, lambda count=count+10: self.do_real_work(count))
class ProgressWindow(tk.Toplevel):
def __init__(self, *args, **kwargs):
tk.Toplevel.__init__(self, *args, **kwargs)
self.label = tk.Label(self, text="0%")
self.label.pack(side="top", fill="both", expand=True)
self.wm_geometry("200x200")
def set(self, value):
if value > 100:
self.destroy()
else:
self.label.configure(text="%s %%" % value)
if __name__ == "__main__":
root = tk.Tk()
App(root).pack(side="top", fill="both", expand=True)
root.mainloop()