1828479 Members
2790 Online
109978 Solutions
New Discussion

TK/TCL HELP

 
hpuxrox
Respected Contributor

TK/TCL HELP

can someone tell my why the puts is not reflecting the variable?

CUT -->

set fp [open "host2"]
while {-1 != [gets $fp line]} {

button .a${line} -text "${line} " -width 20 -command {


puts $line

}

pack .a${line}

}
1 REPLY 1
Mike Stroyan
Honored Contributor

Re: TK/TCL HELP

The {} braces around the command prevent $line from being evaluated until the button is pressed. By that time it has a null value in the context that it is evaluated in.
You can use
-command "puts $line"
if the $line value is always one word.
You can use
-command [list puts $line]
to handle lines that are multiple words. (But it looks like the rest of your example depends on having $line always be one word.)
The quoting issues with -command are covered in depth in the "Quoting hell" topic at http://wiki.tcl.tk/1726