Python Forum
[Tkinter] What causes this pop-up to trigger?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] What causes this pop-up to trigger?
#2
It pops up because you call exit("pop") when you make the button.
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
Reply


Messages In This Thread
What causes this pop-up to trigger? - by Oshadha - Dec-17-2020, 04:40 AM
RE: What causes this pop-up to trigger? - by deanhystad - Dec-17-2020, 05:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] PyQt trigger leaveEvent in parent kainev 5 4,880 Dec-03-2019, 04:22 PM
Last Post: Denni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020