Discussion:
[Tkinter-discuss] how to wait for user input?
stewart at midtoad.homelinux.org ()
2004-10-08 08:11:18 UTC
Permalink
hi all:

I've got a Tkinter app working. One of its methods opens a Pmw combo-box and
present a list of choices. I've added buttons to delete choices, select
choices, and create a new choice. It's this latter button that is causing problems.

When I create a choice, I invoke a method that asks for input on the name of a
choice using an easygui entry field. So far so good. The next thing is to ask
the user to select one of two possible config setting for her choice; I'm doing
that with a top-level widget that contains a button for each of the two
settings. The problem I'm having is that my method doesn't appear to stop and
wait for the user to press a button, but intead goes ahead to the next step,
which is to display the chosen config setting (which of course fails, since no
choice has yet been made).

How do I get the method to stop and wait for the config setting to be made in
the toplevel window? I think that I need the toplevel button to be modal, so
that as soon as it's drawn, execution stops on my choice-creation method.

If this seems too abstract, I can post a sample app that demonstrates the behaviour.

cheers
Stewart
Jeff Epler
2004-10-08 08:32:24 UTC
Permalink
You can use .grab_set() (force keyboard and mouse events to a single window
in the application) and .wm_transient() (give the window the appearance
of a "transient" window aka "dialog" or "secondary window, and force it
to appear above the main application window in stacking order).

To wait for "something to happen", you can use wait_window (handles
events and returns when the window is destroyed) or wait_variable
(handles events and returns when the value of a variable is changed),
or you can have the command= of the OK and Cancel buttons perform the
action, destroy or hide the window, and release the grab, and use
neither of the above.

.grab_release() will let the main window handle events again.
Destroying the secondary window would automatically release grab. I
don't know whether merely withdrawing it would.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20041007/cb4b10ff/attachment.pgp
stewart at midtoad.homelinux.org ()
2004-10-08 11:42:42 UTC
Permalink
Post by Jeff Epler
You can use .grab_set()
Thanks, Jeff, that was just the tip I needed. I did a look-up on .grab_set() and
found some useful additional info in the pages at pythonware.com, e.g.
http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm and
also
http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm.

cheers
Stewart

Continue reading on narkive:
Loading...