Reputation: 59
I made a simple GUI in Tkinter and tried to convert it into an application. There is a manually made exit button in the program that works when it is a python program but not when made into an application. My code is:
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()
Upvotes: 1
Views: 59
Reputation: 1215
Instead of setting command of the button to call exit , just use root.destroy
.
So , you'll have to modify the button declaration line as:
b1 = Button(root,text = " X ", command = root.destroy, bg = None)
Upvotes: 1