combo.tcl 1.9 KB

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