When closing a tkinter window, it's hidden, but persists
When you close the secondary window which is created by the method, it does get destroy
ed if it's closed however by default you close any window. If you want to see for yourself, try adding:
print(root.winfo_children())
that lists the widgets that are direct children to root
, which the Toplevel
you created is a member of, as the very last line to subWindow
.
Further window.protocol("WM_DELETE_WINDOW", callback)
calls the callback
when the default closing window protocol is ongoing, such as click the X button, or Alt-F4. It can be used to ask user things such as: "Do you really want to close?" before closing the window. Though, when you close a window regularly, it is supposed to be destroyed anyway, which means that while top.protocol("WM_DELETE_WINDOW", closeSubWindow)
doesn't raise an error, it is supposed to be redundant, unless the default behavior is overwritten somehow.
While the above may be true, as Bryan points out in the comments, the reference to the created Toplevel
, top
is a local name, which has no meaning outside subWindow
method.