gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:20:46 25 4
gpt4 key购买 nike

我在 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)

关于python - 转换为应用程序后 Quit() 按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47963724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com