我在 TCL 中有这个小循环
for {set i 1} {$i <= $user} {incr i} {
grid [ttk::button .seluser.$i -text "$i" -command { set ::user $i }] -column $i -row 1
}
我收到消息
ERROR can't read "i": no such variable
我认为这是因为-command
像一个新的过程一样工作,这就是为什么它无法识别变量i
。
我不知道该怎么做。有人可以帮助我吗?
最佳答案
尝试用引号代替大括号,以便预先插入$i
。例如,
for {set i 1} {$i <= $user} {incr i} {
grid [ttk::button .seluser.$i -text "$i" -command " set ::user $i "] -column $i -row 1
}
关于tcl - for循环中的按钮命令(没有这样的变量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10801338/