&引用;无效的命令名";W"';在运行tcl脚本时

&引用;无效的命令名";W"';在运行tcl脚本时,tcl,modelsim,invalid-argument,Tcl,Modelsim,Invalid Argument,我在ModelSim中的TCL上制作了一些GUI,但当我运行时,它会导致一些奇怪的错误 # invalid command name "W" # while executing # "$w nearest $y" # (procedure "ListSelectEnd" line 2) 这有点奇怪,因为几乎相似的表达就在那之前。这就是代码: global a proc ScrolledListbox { parent

我在ModelSim中的TCL上制作了一些GUI,但当我运行时,它会导致一些奇怪的错误

# invalid command name "W"
#     while executing
# "$w nearest $y"
#     (procedure "ListSelectEnd" line 2)
这有点奇怪,因为几乎相似的表达就在那之前。这就是代码:

global a
proc ScrolledListbox { parent args } {
    frame $parent
    eval {listbox $parent.list \
        -yscrollcommand [list $parent.sy set] \
        -xscrollcommand [list $parent.sx set]} $args
    scrollbar $parent.sx -orient horizontal \
        -command [list $parent.list xview]
    scrollbar $parent.sy -orient vertical \
        -command [list $parent.list yview]
    pack $parent.sx -side bottom -fill x
    pack $parent.sy -side right -fill y
    pack $parent.list -side left -fill both -expand true
    return $parent.list
}
#-------------------------------------------
proc ListSelect { parent choices } {
    global a
    frame $parent
    ScrolledListbox $parent.choices -width 20 -height 5 \
        -setgrid true
    ScrolledListbox $parent.picked -width 20 -height 5 \
        -setgrid true
    pack $parent.choices $parent.picked -side left \
        -expand true -fill both
    bind $parent.choices.list <ButtonPress-1> \
        {ListSelectStart %W %y}
    bind $parent.choices.list <ButtonRelease-1> \
    lappend a [ListSelectEnd %W %y .top.f.picked.list]
    eval {$parent.choices.list insert 0} $choices
}
#----------------------------------------
proc ListSelectStart { w y } {
    $w select anchor [$w nearest $y]
}
#-----------------------------------------
proc ListSelectEnd { w y list } {
    $w select set anchor [$w nearest $y]
    foreach i [$w curselection] {
        $list insert end [$w get $i]
        lappend listin [$w get $i]
    }
    return $listin
}
#--------------------------------------------
proc tosignal {parent val} {
    global a
    for {set i 0} {$i<[llength $a]} {incr i} {
        force -freeze sim:/chema_tb/m1/[lindex $a $i] $val 0
    }
    run 1000 ns
    destroy $parent
    return 1
}
#------------------------------------------------
proc form {} {
    global a
    toplevel .top 
    set filename signalfile.txt
    set in [open $filename]
    while {[gets $in var]>-1} {
        lappend spisn [lindex $var 0]
    }
    ListSelect .top.f $spisn
    button .top.okb  -text  OK -width 20 -height 2 -font {-size 15 -family Times -weight bold} \
        -fg blue -anchor center  -command {tosignal .top 0 }
    pack .top.f .top.okb -expand true
}
全局a
proc scrolled列表框{parent args}{
帧$parent
eval{listbox$parent.list\
-yscrollcommand[list$parent.sy set]\
-xscrollcommand[list$parent.sx set]}$args
滚动条$parent.sx-水平方向\
-命令[list$parent.list xview]
滚动条$parent.sy-垂直定向\
-命令[list$parent.list yview]
包装$parent.sx-侧面底部-填充x
包装$parent.sy-右侧-填充y
pack$parent.list-左侧-两侧填充-展开为真
返回$parent.list
}
#-------------------------------------------
proc ListSelect{父选项}{
全球a
帧$parent
滚动列表框$parent.choices-宽20-高5\
-设置网格为真
ScrolledListbox$parent.picked-宽20-高5\
-设置网格为真
打包$parent.choices$parent.picked-左侧\
-展开true-填充两者
绑定$parent.choices.list\
{ListSelectStart%W%y}
绑定$parent.choices.list\
lappend a[ListSelectEnd%W%y.top.f.picked.list]
eval{$parent.choices.list插入0}$choices
}
#----------------------------------------
proc ListSelectStart{w y}{
$w选择锚[$w最近的$y]
}
#-----------------------------------------
proc ListSelectEnd{w y list}{
$w选择设置锚点[$w最近的$y]
foreach i[$w]{
$list insert end[$w get$i]
lappend listin[$w获取$i]
}
返回$listin
}
#--------------------------------------------
proc tosignal{parent val}{
全球a
对于{set i0}{$i-1}{
lappend spisn[lindex$var 0]
}
ListSelect.top.f$spisn
button.top.okb-文本OK-宽度20-高度2-字体{-大小15-家庭时间-粗体权重}\
-fg蓝色-锚定中心-命令{tosignal.top 0}
pack.top.f.top.okb-展开true
}

如果你能帮助我,我将非常感激

问题在于这些线路:

bind $parent.choices.list <ButtonRelease-1> \
lappend a [ListSelectEnd %W %y .top.f.picked.list]
或者这个:

bind $parent.choices.list <ButtonRelease-1> {
    ListSelectEnd %W %y .top.f.picked.list
}
bind $parent.choices.list <ButtonRelease-1> \
    [list ListSelectEnd %W %y .top.f.picked.list]
bind$parent.choices.list{
ListSelectEnd%W%y.top.f.picked.list
}
或者这个:

bind $parent.choices.list <ButtonRelease-1> {
    ListSelectEnd %W %y .top.f.picked.list
}
bind $parent.choices.list <ButtonRelease-1> \
    [list ListSelectEnd %W %y .top.f.picked.list]
bind$parent.choices.list\
[列表选择结束%W%y.top.f.picked.list]

在这种情况下,使用哪一种并不重要。(除空格外,前两个是等效的。当您在脚本中绑定变量时,第三个更有用,但在本例中您没有这样做。)

作为一般提示,如果使用普通缩进,调试代码会容易得多。非常感谢!这很有帮助:D
bind$parent.choices.list\{ListSelectEnd%W%y.top.f.picked.list}
但在出现新错误之后<代码>#回溯:无法读取“a”:没有这样的变量#在执行#“llength$a”#(过程“tosignal”第3行)我不知道为什么,因为
全局a
是在循环之前编写的:/