(n00b) Tkinter trouble

Jason Swails jason.swails at gmail.com
Tue Nov 15 22:02:25 EST 2011


On Tue, Nov 15, 2011 at 12:32 AM, Chris Angelico <rosuav at gmail.com> wrote:

>
> As a general rule, if any parent is invisible, you won't see the
> child, and if any parent is disabled, you can't access the child.


Yea, I'm becoming more familiar and comfortable with the GUI hierarchy as I
play around.  I do like how simple it is to test a concept in Tkinter (just
a couple lines builds you a window with any kind of widget you want).


> You
> may find that there's even a one-line command that will disable the
> window, open a new window, wait for the new window to close, and
> automatically reenable the window - an "open modal dialog" function or
> something.
>

Apparently I could not do what I was wanting to (state=DISABLED is not a
valid option to Toplevel).  What I wanted to do was something similar to
what the dialogs were doing from tkMessageBox.  The window didn't appear
changed, but no buttons could be clicked.  After looking through the
tkMessageBox.py source code, I found the method I was looking for:
grab_set.  Essentially, I just have to have my new window call its
grab_set() method to hog all events.  Not really "disabling" the root
window (which is why I had a hard time finding it on Google), but it's the
exact behavior I was looking for.
http://www.python-forum.org/pythonforum/viewtopic.php?f=15&t=4930 was
helpful here.

The only other approach I (successfully) tried was to use the .withdraw()
method on the window during the constructor of the *new* window and execute
.deiconify() on it during the new window's destroy() method (before calling
Toplevel's destroy on self).  I still like the first way better.

Thanks!
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111115/267427d9/attachment-0001.html>


More information about the Python-list mailing list