转换为应用程序后退出()按钮不起作用

问题描述 投票:1回答:1

我在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()
python python-3.x tkinter
1个回答
1
投票

只需使用root.destroy,而不是设置按钮的命令来调用exit。

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

b1 = Button(root,text = " X ",  command = root.destroy, bg = None)
© www.soinside.com 2019 - 2024. All rights reserved.