stopping tkinter callbacks

Matthew Dixon Cowles matt at mondoinfo.com
Sun Aug 27 21:36:58 EDT 2000


On Sun, 27 Aug 2000 17:58:48 -0700, Bob van der Poel
<bvdpoel at uniserve.com> wrote:
>Is it possible to stop the callback/binding in tkinter for a moment
>which some other stuff is going on. Here's my problem:
>
>  - A button or menu is bound to the function Spam
>  - when Spam is called it has to create a complicated window. This
>    takes a second or so. Once the window is created it
>    grabs the focus, so hitting the button again is ignored
>    since the window with the button is no longer active.
>  - Life is wonderful
>
>However, if the user clicks the button a 2nd time while the Spam window
>is being created...2 (or more) windows are now created.
>
>So, in Spam I need to turn off binding handling until it grabs the
>focus. Ideas???

Dear Bob,
Depending on the structure of your code, it may not be practical to do
this but in similar situations, I've used a primitive lock to ensure
that only one copy of a particular routine is running at a time. If it
works for you, that may be simpler than unbinding and rebinding the
function.

You might have the long-running operation set a flag (perhaps an
attribute of its object) that indicates that it has started and reset
it when done. Before setting the flag, it can check to see if the flag
is already set and exit without doing anything if it is.

You might also want to give your user a visual cue that the operation
might take a while by setting the mouse pointer to the wristwatch icon

root.configure(cursor="watch")

You can set it back to the default by using "" for the cursor name.
(The various cursors are listed in

/usr/X11R6/include/X11/cursorfont.h

on my system.)

Regards,
Matt



More information about the Python-list mailing list