3 # This demonstration script creates several combobox widgets.
5 if {![info exists widgetDemo]} {
6 error "This script should be run from the \"widget\" demo."
14 wm title $w "Combobox Demonstration"
15 wm iconname $w "combo"
18 ttk::label $w.msg -font $font -wraplength 5i -justify left -text "Three different\
19 combo-boxes are displayed below. You can add characters to the first\
20 one by pointing, clicking and typing, just as with an entry; pressing\
21 Return will cause the current value to be added to the list that is\
22 selectable from the drop-down list, and you can choose other values\
23 by pressing the Down key, using the arrow keys to pick another one,\
24 and pressing Return again. The second combo-box is fixed to a\
25 particular value, and cannot be modified at all. The third one only\
26 allows you to select values from its drop-down list of Australian\
28 pack $w.msg -side top -fill x
30 ## See Code / Dismiss buttons
31 set btns [addSeeDismiss $w.buttons $w {firstValue secondValue ozCity}]
32 pack $btns -side bottom -fill x
35 pack $w.f -fill both -expand 1
38 set australianCities {
39 Canberra Sydney Melbourne Perth Adelaide Brisbane
40 Hobart Darwin "Alice Springs"
42 set secondValue unchangable
45 ttk::labelframe $w.c1 -text "Fully Editable"
46 ttk::combobox $w.c1.c -textvariable firstValue
47 ttk::labelframe $w.c2 -text Disabled
48 ttk::combobox $w.c2.c -textvariable secondValue -state disabled
49 ttk::labelframe $w.c3 -text "Defined List Only"
50 ttk::combobox $w.c3.c -textvariable ozCity -state readonly \
51 -values $australianCities
52 bind $w.c1.c <Return> {
53 if {[%W get] ni [%W cget -values]} {
54 %W configure -values [concat [%W cget -values] [list [%W get]]]
58 pack $w.c1 $w.c2 $w.c3 -side top -pady 5 -padx 10
59 pack $w.c1.c -pady 5 -padx 10
60 pack $w.c2.c -pady 5 -padx 10
61 pack $w.c3.c -pady 5 -padx 10