Try to get the toplevel window

This is overly conservative as it is unlikely that our widgets
are not inside a toplevel window.