Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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