Python Tkinter应用程序无法正常退出
发布时间:2020-12-20 11:18:41 所属栏目:Python 来源:网络整理
导读:from TKinter import *class Ui(Frame): def __init__(self) Frame.__init__(self,None) self.grid() bquit=Button(self,text="Quit",command=self.quit_pressed) bquit.grid(row=0,column=0) def quit_pressed(self): self.destroy()app=Ui()app.mainloop()
from TKinter import * class Ui(Frame): def __init__(self) Frame.__init__(self,None) self.grid() bquit=Button(self,text="Quit",command=self.quit_pressed) bquit.grid(row=0,column=0) def quit_pressed(self): self.destroy() app=Ui() app.mainloop() 当我按下“退出”按钮时,为什么这个Tkinter程序没有正确结束? 解决方法
使用self.destroy()你只是破坏Frame而不是顶级容器,你需要做self.master.destroy()才能正确退出
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |