user14599750
user14599750

Reputation:

Is there a way to checkt the state of a window (whether its open or closed) in tkinter

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

Answers (1)

Bryan Oakley
Bryan Oakley

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

Related Questions