[vtkusers] Question about tcl/tk-VTK application,..
Barry Hathaway
bhathaw1 at nycap.rr.com
Fri Sep 11 14:06:21 EDT 2009
Substitution occurs within strings and not within {}s. So instead of:
button ... -command {puts $a}
use
button ... -command "puts $a"
so that the command gets generated as a constant string.
Barry
Miguel Ángel Rodríguez Florido wrote:
> Hi all,
>
> Sorry, because this question is more related to tcl/tk, but I know
> that many people that works under VTK uses Tcl/Tk..so sorry again for
> people that not.
>
> My question is very simple, but I haven't found how to do that.
>
> I have a Tcl/Tk procedure like:
>
> proc myproc {vars} {
>
> code
>
> foreach a $list {
> button .blabla.$a -text $a -command {puts $a}
> }
>
> }
>
>
> However the foreach variable $a doesn't exist in the -command option.
> I mean, I got an error when it runs this puts: puts $a.
> If I do global this variable: global a, I only got the last value
> of $a.
>
> So I understand that the foreach command is running first, and
> when it finishs, the tcl run the -command option of the tk button.
>
> How can I access to the variable "a" in the -command button
> option??. I mean, how can I get the value of "a" at foreach step in
> the -command option?
>
> Thank you very much.
> Best regards.
>
More information about the vtkusers
mailing list