Next: Validating User Inputs Up: Getting Started: the Previous: Accessing The Value

 

Disabling Callbacks Temporarily 

Now, if you want to change a value from within the program, you have to disable the callback. The reason is that the callback runs whenever you (as well as the user) makes a change. In particular, if you make a change within the callback procedure and forget to disable the callback, it will recursively call itself and enter an infinite loop. To avoid this problem, you should use the -disablecallback option. Here is an example:

tixControl .c -command addOne

proc addOne {value} {
.c config -disablecallback true
.c config -value [incr value]
.c config -disablecallback false
}

The procedure addOne adjusts the value of .c by one whenever the user enters a new value into .c. Notice that it is necessary to set -disablecallback here or otherwise addOne will be infinitely recursed! That is because addOne is called every time the value changes, either by the user or by the program.


http://tix.sourceforge.net