Tkinter: user vs. program events

Andrew M. Kuchling akuchlin at mems-exchange.org
Wed Feb 23 16:08:09 EST 2000


"Fredrik Lundh" <effbot at telia.com> writes:
> why not just add a semaphore?
> 
>     def adjust_light(self):
>         if self.status_update:
>             return
>         ...
>     def handle_status_event(self):
>         ...
>         try:
>             self.status_update = 1
>             self.light_scale.set(value)
>         finally:
>             self.status_update = 0

That's what I first thought, but it doesn't work.  The
light_scale.set() call doesn't recursively invoke adjust_light().
Instead, I assume the .set() call adds an event to a queue inside Tk
which will be handled on re-entering Tk's main loop.  In other words,
handle_status_event() is called and it returns, and *then*
adjust_light() is called as a result of the set.

The solution is probably "Don't do that, then"; I should have text
labels that give the current state, and leave the scale widget to only
be manipulated by the user.  That way the user don't have to worry
about an ill-timed status update suddenly moving the setting while
trying to fine-tune the setting.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
    "The thing is, Doctor, is there anything I can do?"
    "Yes, pass me a silicon rod, will you?" <stirs his tea with it>
    -- The Brigadier and the Doctor, in "The Three Doctors"




More information about the Python-list mailing list