Python 2.7 Tkinter on close function

im making a small app which opens a box using Tkinter when a certain condition is reached.

I dont want to spam the user with theses boxes so i want tkinter to set a variable to True when it starts up, then as it closes set it back to False.

Im making a down website checker/notifier so once the website is back up you get a pop up box letting you know. Right now if you close the box the code will continue and the box will pop up again. However the real problem is the code wont continue in the background.

If i make the code continue to run in the background the every 5 seconds of the conditions being met, another box will pop up and eventually spam the user which is something i dont want.

is there a way to check if there is a tkinter box open, or set a value to false when the close button (or X button) is pressed ?


Solution 1:

You can redefine what the close button does:

win = Toplevel()
win.protocol('WM_DELETE_WINDOW', close(win))

def close(window):
  window.withdraw()
  someboolean = False

Hope this helps!