Tkinter: user vs. program events

Andrew M. Kuchling akuchlin at mems-exchange.org
Tue Feb 22 13:52:36 EST 2000


I've been trying to figure out how to distinguish between Tkinter
events that come from a user and ones that originate from changing the
value of a widget.  Is this possible?

Here's the motivating example.  I have a Scale widget for indicating
light intensity:

 self.light_scale = Tkinter.Scale(f, command = self.adjust_light)

adjust_light() is a method that takes the current value of the scale
widget, and sends off a command to change light intensity.  The
Tkinter program also receives updates on the current state, and
changes the scale widget to match the current value, with
self.light_scale.set( <value> ) .

The problem is that the light_scale.set() call causes the associated
command to be run, so a command is sent off changing the light
intensity, which causes another status update to be sent out, which
changes the setting, and so forth.

So, how would you do this in Tkinter?  Can I distinguish between
events generated by a user and by a .set() call?  Should
adjust_light() be bound to some different event?  Or should I change
the binding of the widget on every update()?

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Science itself, therefore, may be regarded as a minimal problem, consisting of
the completest possible presentment of facts with the least possible
expenditure of thought.
    -- Ernst Mach




More information about the Python-list mailing list