Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Substitution in Tcl/Tk 1

Status
Not open for further replies.

SloppyNick

Programmer
Jun 11, 2007
6
US
I am trying to create a dynamic GUI in Tcl/Tk. I have a spinbox that the user can manipulate, and I have a number of checkbuttons that I want to be able to refer to dynamically.

So, for example, in the spinbutton callback, $value refers to the value of the spinbutton. chk$value is the name of a checkbutton that I want to be able to manipulate. However, to access this variable, I would have to reference it with '$', which would look like $chk($value), assuming that parentheses would cause $value to be substituted first. However, I understand that all substitutions are done in one step. Is there any way to get around this? I have tried messing around with {} and eval, but to no avail.
 
I'm not sure I follow, but does $chk{$value} not do what you want? What does it do (and why isn't that what you want)?

_________________
Bob Rashkin
 
No, that doesn't work. I get the error "Can't read 'chk': no such variable".

Basically, if the spinbutton reads "1", then I want to be able to reference the variable named "chk1". I can get the string "chk1" by doing chk$value. However, to get the value stored by that variable, I would have to do $chk$value, which gives me the same error. I want to force tcl to substitute $value first, then $chk, but I don't know how to do that, or if it is even possible.
 
% set chk1 42
42
% puts $chk1
42
% set a 1
1
% set cmdstr {puts $chk}
puts $chk
% append cmdstr $a
puts $chk1
% eval $cmdstr
42
%


_________________
Bob Rashkin
 
That worked, Bong. Thanks for the posts, Bong and prex1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top