combo.tcl 2.0 KB

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