I need to be able to check if a tkinter widget is visible (if its pack
or grid
method has been called).
I'm currently doing the following:
def is_visible(widget):
try:
widget.pack_info()
except tk.TclError:
# pack_info raises if pack hasn't been
# called yet.
return bool(widget.grid_info())
# grid_info returns {} if grid hasn't been
# called yet.
else:
return True
Is there any way in which I could improve this code, by using a standard widget attribute, or through some other solution that's less 'hacky'?