Python Tkinter 应用程序未正确退出 [英] Python Tkinter application doesn't quit properly

查看:38
本文介绍了Python Tkinter 应用程序未正确退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 程序没有正确结束?

Why doesn't this Tkinter program end properly when I press the "Quit" button?

推荐答案

使用 self.destroy() 你只是在销毁 Frame,而不是顶层容器,你需要做 self.master.destroy() for它正确退出

With self.destroy() you're just destroying the Frame, not the the top level container, you need to do self.master.destroy() for it to exit correctly

这篇关于Python Tkinter 应用程序未正确退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆