1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
package require Tk
set b [button .quit -text quitter -command {destroy .}]
proc select {parent values} {
frame $parent
set choices [scrolled_listbox $parent.choices \
-width 20 -height 5 ]
set picked [scrolled_listbox $parent.picked \
-width 20 -height 5 ]
pack $parent.choices $parent.picked -side left \
-expand true -fill both
bind $choices <ButtonRelease-1> \
[list listTransferSel %W $picked]
bind $picked <ButtonRelease-1> \
{listdeletesel %W %y}
foreach x $values {
$choices insert end $x
}
}
#====================================================================================================
proc listTransferSel {src dst} {
foreach i [$src curselection] {
$dst insert end [$src get $i]
}
set u [expr $i + 1 ]
puts stdout "la variante active choisie est la $u variante "
}
#=================================================================================================
proc listdeletesel {w y} {
foreach i [lsort -integer -decreasing [$w curselection]] {
$w delete $i
}
}
#=================================================================================================
proc list_selectvalues {parent} {
set picked $parent.picked.list
set result {}
foreach i [$w curselection] {
lappend result [$w get $i]
}
}
#=================================================================================================
proc scrolled_listbox { f args } {
frame $f
listbox $f.list
eval {$f.list configure} $args
scrollbar $f.xscroll -orient horizontal \
-command [list $f.list xview]
scrollbar $f.yscroll -orient vertical \
-command [list $f.list yview]
grid $f.list -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.list
}
#=================================================================================================
proc valider {} {
list_selectvalues .mel
puts stdout "le choix de la variante active à été effectué"
puts stdout "la variante est $result"
}
#=================================================================================================
set list_variante {voie_a voie_b all}
select .mel $list_variante
set a [button .ok -text "valider la variante" -command valider]
pack .mel -expand true -fill both
pack $a -fill x -expand true
pack $b -fill x -expand true
tkwait window .
exit |
Partager