Tcl 如何防止每次选择checkbutton时关闭菜单

Tcl 如何防止每次选择checkbutton时关闭菜单,tcl,tk,Tcl,Tk,下面是我的代码示例。 每当需要选择几个选项时,重新打开菜单是非常烦人的。由于每次选中复选框时,菜单都会自动关闭。 我怎样才能预防它 #!/usr/bin/env wish frame .top pack .top -expand yes -fill both wm title . TEST menubutton .top.fillmet -text "select fill metals" -menu .top.fillmet.mtls set m .top.fillmet.mtl

下面是我的代码示例。 每当需要选择几个选项时,重新打开菜单是非常烦人的。由于每次选中复选框时,菜单都会自动关闭。 我怎样才能预防它

#!/usr/bin/env wish


frame .top
pack .top -expand yes -fill both 
wm title . TEST

menubutton .top.fillmet -text "select fill metals" -menu .top.fillmet.mtls  

set m .top.fillmet.mtls
menu $m

$m add checkbutton -label "fill m2" -variable fillm2 -onvalue "fillm2" -offvalue ""

$m add checkbutton -label  "fill m3"  -variable fillm3  -onvalue "fillm3"  -offvalue ""
$m add checkbutton -label  "fill m4"  -variable fillm4  -onvalue "fillm4"  -offvalue ""
$m add checkbutton -label  "fill m5"  -variable fillm5  -onvalue "fillm5"  -offvalue ""
$m add checkbutton -label  "fill m6"  -variable fillm6  -onvalue "fillm6"  -offvalue ""
$m add checkbutton -label  "fill m7"  -variable fillm7  -onvalue "fillm7"  -offvalue ""
$m add checkbutton -label  "fill m8"  -variable fillm8  -onvalue "fillm8"  -offvalue ""
$m add checkbutton -label  "fill m9"  -variable fillm9  -onvalue "fillm9"  -offvalue ""
$m add checkbutton -label  "fill m10" -variable fillm10 -onvalue "fillm10" -offvalue ""
$m add checkbutton -label  "fill m11" -variable fillm11 -onvalue "fillm11" -offvalue ""
$m add checkbutton -label  "fill m12" -variable fillm12 -onvalue "fillm12" -offvalue ""


pack .top.fillmet

也许另一种方法更适合这个特定的用户界面

这将显示一个新的顶级窗口,其中包含 可以选择。全局
fillm
数组将填充 结果

proc doOptions{}{
全局填充
集合w.optfillmet
顶级$w
对于{set i 2}{$i<13}{incr i}{
checkbutton$w.cb$i-文本“fill m$i”-变量fillm($i)\
-onvalue fillm$i-offvalue“”
包装$w.cb$i-in$w-侧面顶部-锚定w
}
按钮$w.b-文本关闭-命令[列表销毁$w]
包装$w.b-在$w-侧面顶部-锚e
}
框架,上面
pack.top-展开yes-填充两个
wm标题。试验
#.top.fillmet.mtls;#冗余线路
菜单,顶部,圆角
.top.fillmet添加命令-标签“选择填充金属”-命令选项
. 配置-menu.top.fillmet

也许一种不同的方法更适合这个特定的用户界面

这将显示一个新的顶级窗口,其中包含 可以选择。全局
fillm
数组将填充 结果

proc doOptions{}{
全局填充
集合w.optfillmet
顶级$w
对于{set i 2}{$i<13}{incr i}{
checkbutton$w.cb$i-文本“fill m$i”-变量fillm($i)\
-onvalue fillm$i-offvalue“”
包装$w.cb$i-in$w-侧面顶部-锚定w
}
按钮$w.b-文本关闭-命令[列表销毁$w]
包装$w.b-在$w-侧面顶部-锚e
}
框架,上面
pack.top-展开yes-填充两个
wm标题。试验
#.top.fillmet.mtls;#冗余线路
菜单,顶部,圆角
.top.fillmet添加命令-标签“选择填充金属”-命令选项
. 配置-menu.top.fillmet

我认为你的建议非常好。然而,在我的示例中,我可以通过单击虚线来使用相同的技术。所以菜单将变成独立的窗口,在我选中复选框后不会自动关闭。也许你知道更优雅的解决方案。我认为你的建议真的很好。然而,在我的示例中,我可以通过单击虚线来使用相同的技术。所以菜单将变成独立的窗口,在我选中复选框后不会自动关闭。也许你知道更优雅的解决方案。
proc doOptions { } {
  global fillm

  set w .optfillmet
  toplevel $w
  for {set i 2} {$i < 13} {incr i} {
     checkbutton $w.cb$i -text "fill m$i" -variable fillm($i) \
          -onvalue fillm$i -offvalue ""
     pack $w.cb$i -in $w -side top -anchor w
  }
  button $w.b -text close -command [list destroy $w]
  pack $w.b -in $w -side top -anchor e
}

frame .top
pack .top -expand yes -fill both 
wm title . TEST

# .top.fillmet.mtls ; # redundant line
menu .top.fillmet 
.top.fillmet add command -label "select fill metals" -command doOptions
. configure -menu .top.fillmet