I'm aware of this discussion: (How do I close a tkinter window?)
I'm curious as to how this changes when doing the same thing in a Jupyter notebook.
test code:
from tkinter import *
def close_window():
root.destroy()
#exit()
root = Tk()
#root.protocol("WM_DELETE_WINDOW", close_window)
Button(root, text="Close", command=close_window).pack()
root.mainloop()
Works fine when I run the script from the command line. Running it from a Jupyter notebook hangs when trying to close the tkinter window (using the root.protocol doesn't change anything).
If I include the exit(), the window does close, but the kernel dies. Is there a way to close the tkinter window and not have the kernel die? After investigating this for quite a while, it seems like the outcomes are mutually exclusive. I'm hoping for an explanation that's more than "that's just the way it is" for the benefit of students. Or, a workaround. In my fantasy world, the Jupyter code cell can be run repeatedly, closing the window each time, without the kernel dying.
Apologies for formatting issues – I rarely post to stackoverflow...