Dec-17-2020, 05:58 AM
(This post was last modified: Dec-17-2020, 06:02 AM by deanhystad.)
It pops up because you call exit("pop") when you make the button.
You probably want you code to look more like this:
https://docs.python.org/3.9/library/dialog.html
btnExit = Button(f1, padx = 16, pady = 8, bd = 16, fg = "black", font = ("arial", 16, "bold"), width = 10, text = "Exit", bg = "powder blue", command = exit("pop")) .grid(row = 8, column = 2) # <- Calling exit("pop")There are several problems here. The first is you are calling exit("pop") when you make the button. The second is that command=None because exit("pop") returns None when called. The third is that btnExit is also None. After you make the Button you call .grid(row=8, column=2). .grid() returns None, so btnExit is None. And the final problem is that you have a lot of lines that are too long. Your programs will be easier to work with if all you lines are less than 80 characters long.
You probably want you code to look more like this:
btnExit = Button(f1, padx=16, pady=8, bd = 16, fg = "black", font = ("arial", 16, "bold"), width = 10, text = "Exit", bg = "powder blue", command = lambda: exit("pop")) btnExit.grid(row = 8, column = 2)Instead of a lambda you could also use a functools.partial, or you could split the exit() function in half.
def exit_program: root.destroy def verify_exit(): popup_msg("exit")I would have the verify_exit() function create a popup dialog. You should only ever call Tk() once in a program. Read about tkinter dialogs here:
https://docs.python.org/3.9/library/dialog.html