【发布时间】:2020-07-29 13:52:08
【问题描述】:
在创建 Python Tkinter 程序时,我希望创建一个关闭程序的按钮。我试过了
#with master = Tk()
master.quit()
方法。它对我的程序完全没有任何作用——除了停止任何工作,尽管我没有收到任何追溯。
我试过的另一种方法是:
#with master = Tk()
master.destroy()
这又对我的程序没有任何作用——它确实给了我一个回溯错误,尽管它是:
_tkinter.TclError: can't invoke "button" command: application has been destroyed
我的完整代码是:
from tkinter import *
master = Tk()
exitbutton = Button(master,text="Exit",(all the other personalization stuff here),command=(master.quit()))
#or I used master.destroy() in the command area.
exitbutton.grid(column=0,row=0)
以上方法均无效。
非常感谢 (未来)
【问题讨论】:
-
看到这个问题link
标签: python user-interface tkinter grid exit