Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 转换为应用程序后,Quit()按钮不起作用_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 转换为应用程序后,Quit()按钮不起作用

Python 转换为应用程序后,Quit()按钮不起作用,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我在Tkinter中制作了一个简单的GUI,并试图将其转换为一个应用程序。程序中有一个手动创建的退出按钮,当它是python程序时可以工作,但当它被制作成应用程序时不能工作。我的代码是: def exit(): quit() def main(): root = tk.Tk() top = Frame(root) bottom = Frame(root) top.config(bg="lightgray") top.pack(side=TOP

我在Tkinter中制作了一个简单的GUI,并试图将其转换为一个应用程序。程序中有一个手动创建的退出按钮,当它是python程序时可以工作,但当它被制作成应用程序时不能工作。我的代码是:

def exit():
    quit()
def main():

    root = tk.Tk()

    top = Frame(root)
    bottom = Frame(root)

    top.config(bg="lightgray")
    top.pack(side=TOP)

    bottom.config(bg="gray")
    bottom.pack(side=BOTTOM, fill=BOTH, expand=True)
    root.title("Quote of the Day")
    root.overrideredirect(True)

    root.lift()
    root.wm_attributes("-transparentcolor", "white")
    root.columnconfigure(0, weight=1)
    root.rowconfigure(1, weight=1)
    root.attributes('-alpha', 0.8)
    root.iconbitmap("icon.png")

    b1 = Button(root,text = " X ",  command = exit, bg = None)
    b1.config(width = 1, height = 1, borderwidth = 0)

    b1.pack(in_=top, side=RIGHT)
    root.mainloop()

if __name__==('__main__'):
    main()

不要将按钮的命令设置为调用exit,只需使用
root.destroy

因此,您必须将按钮声明行修改为:

b1 = Button(root,text = " X ",  command = root.destroy, bg = None)

command=root.destroy
可能效果更好。我相信
quit()。非常感谢。请提供一个使用的示例。您的代码不完整。