Reputation:
I wanted to know whether it is possible to check if a window is closed or open like so:
from tkinter import *
root = Tk()
print(# The root's state.)
Upvotes: 0
Views: 1911
Reputation: 385910
You can use winfo_viewable
to determine if the window is visible.
state = "viewable" if root.winfo_viewable() else "hidden"
This will work for any widget, not just the root window. This is what the official documentation says:
Returns 1 if window and all of its ancestors up through the nearest toplevel window are mapped. Returns 0 if any of these windows are not mapped.
Upvotes: 1