2016-06-14 85 views
1

以下是我的代码示例。 每次需要选择多个选项时,重新打开菜单是非常烦人的。由于每次选中复选框,菜单都会自动关闭。 我该如何预防?如何防止每次选择checkbutton时关闭菜单

#!/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 

enter image description here

回答

0

也许不同的方法会更好地为这个特殊的用户界面?

这将显示一个新的顶层窗口,其中包含一个选项列表 可以选择。全球fillm阵列将填充 结果。

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

我认为你的建议真的很好。 但是我可以使用相同的技术,只需点击我的示例中的虚线即可。因此,选择复选框后,菜单将变成独立窗口,并且不会自动关闭。可能是你知道更优雅的解决方案。 –