tags:

views:

11

answers:

1

I have a Tkinter GUI where there is a Scale object. I have a callback assigned (by the command constructor parameter) to perform an action when the user changes the scale position. However, there is also a case where the value represented by the scale is modified externally, and so I set the scale position using Scale.set(). In this case, I want to set the scale, but not trigger the callback, since the rest of the program already knows about the change. However, I notice that the callback is indeed triggered by set().

Is it possible to do one of:

  1. Set the scale value without triggering the callback.

  2. Differentiate in the callback whether it was triggered by user interaction or by Scale.set() being called.

Thanks.

A: 

There is nothing specifically built-in to Tkinter to solve this. It's really a simple problem to solve though: remove the callback, set the value, add the callback. Or, set a global flag and check for that flag in the callback.

There are ways to solve the problem -- subclass the widget, for example -- but that doesn't really buy you anything. Just go with the simple solution and move on to more interesting problems.

Bryan Oakley
Okay, I'll probably use the flag approach. Thanks.
Steve