Let's see... You've got a couple of potential problems areas, if I understand your summary correctly.
You wrote: "I thought button variables were global?" More or less. The variables you use for the
-variable attributes must be the name of global variables. When you click the button, the
-value you specified for that radiobutton is assigned to the global variable; if the variable doesn't already exist, Tcl creates it in the global scope.
However, you also wrote: "Since $x($c) is defined when the radiobutton is clicked, why can't the command which is also called by the radiobutton recognize the variable?"
In Tcl all callbacks (code associated with
-command attributes, timer events registered with the
after command, handlers registered with the
fileevent command, etc.) are executed in the global scope. Doesn't sound like a problem, since it sounds as though the
x array variable we're talking about seems to be in the global scope.
However, if your callback consists of calling a procedure, then the procedure executes in its own local scope. And to access global variables from within a procedure, you have to use the
global command within the procedure. In other words, you'd need something like this:
Code:
radiobutton .node$c.type1010 -variable x($c) -value 1 -command update
proc update {} {
# We're now in a scope local
# to the update procedure
global x
# Etc...
}
Which brings up another potential problem. If you've used "update" as the name of a procedure, change it. Tcl has a built-in
update command, which is used to process any pending events and refresh the screen. Tcl doesn't "protect" built-in procedures; it's quite possible to overwrite or redefine them. Usually, it's a bad idea unless you really know what you're doing.
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax