2016-06-14 8 views
1

Folgendes ist mein Codebeispiel. Es ist sehr ärgerlich, das Menü jedes Mal erneut zu öffnen, wenn mehrere Optionen ausgewählt werden müssen. Da jedes Kontrollkästchen aktiviert war, wurde das Menü automatisch geschlossen. Wie kann ich das verhindern?So verhindern Sie, dass das Menü jedes Mal geschlossen wird, wenn Sie die Option "Checkbutton" auswählen

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

Antwort

0

Vielleicht eine andere Methode wäre besser für diese spezielle Benutzeroberfläche?

Dies zeigt ein neues Toplevel-Fenster mit einer Liste von Optionen an, die ausgewählt werden kann. Das globale Array fillm wird mit den Ergebnissen gefüllt.

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

Ich denke, dass Ihr Vorschlag wirklich gut ist. Allerdings kann ich die gleiche Technik nur durch Klicken auf die gestrichelte Linie in meinem Beispiel verwenden. Das Menü wird also zu einem unabhängigen Fenster und wird nicht automatisch geschlossen, nachdem ich das Kontrollkästchen ausgewählt habe. Könnte sein, dass Sie eine elegantere Lösung kennen. –