tcl - for循环中的按钮命令(没有这样的变量)

标签 tcl

我在 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/

相关文章:

Java:迭代 tcl 字典

macos - 苹果操作系统 X : Can I write application files within the app bundle?

string - TCL 字符串前置

tcl - 获取TCL中执行代码的行号

linux - 执行不带扩展名的 CGI 文件

TCL CSV 引用字符

linux - 打补丁后使用 .sh 脚本自动化 ZRP 协议(protocol)

TCL : Is there any command to get package location and procedure names inside that package?

tcl - 创建一个仅支持我提供的命令的 TCL 解释器

java - 尝试从 Android 到服务器的 SSL 连接时出现 "no shared cipher"错误