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