gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.5KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: ComboBox.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "widget": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program using tixwish.
  12. # This file demonstrates the use of the tixComboBox widget, which is close
  13. # to the MS Window Combo Box control.
  14. #
  15. proc RunSample {w} {
  16. # Create the comboboxes on the top of the dialog box
  17. #
  18. frame $w.top -border 1 -relief raised
  19. # $w.top.a is a drop-down combo box. It is not editable -- who wants
  20. # to invent new months?
  21. #
  22. # [Hint] The -options switch sets the options of the subwidgets.
  23. # [Hint] We set the label.width subwidget option of both comboboxes to
  24. # be 10 so that their labels appear to be aligned.
  25. #
  26. tixComboBox $w.top.a -label "Month: " -dropdown true \
  27. -command cbx:select_month -editable false -variable demo_month \
  28. -options {
  29. listbox.height 6
  30. label.width 10
  31. label.anchor e
  32. }
  33. # $w.top.b is a non-drop-down combo box. It is not editable: we provide
  34. # four choices for the user, but he can enter an alternative year if he
  35. # wants to.
  36. #
  37. # [Hint] Use the padY and anchor options of the label subwidget to
  38. # aligh the label with the entry subwidget.
  39. # [Hint] Notice that you should use padY (the NAME of the option) and not
  40. # pady (the SWITCH of the option).
  41. #
  42. tixComboBox $w.top.b -label "Year: " -dropdown false \
  43. -command cbx:select_year -editable true -variable demo_year \
  44. -options {
  45. listbox.height 4
  46. label.padY 5
  47. label.width 10
  48. label.anchor ne
  49. }
  50. pack $w.top.a -side top -anchor w
  51. pack $w.top.b -side top -anchor w
  52. # Insert the choices into the combo boxes
  53. #
  54. $w.top.a insert end January
  55. $w.top.a insert end February
  56. $w.top.a insert end March
  57. $w.top.a insert end April
  58. $w.top.a insert end May
  59. $w.top.a insert end June
  60. $w.top.a insert end July
  61. $w.top.a insert end August
  62. $w.top.a insert end September
  63. $w.top.a insert end October
  64. $w.top.a insert end November
  65. $w.top.a insert end December
  66. $w.top.b insert end 1992
  67. $w.top.b insert end 1993
  68. $w.top.b insert end 1994
  69. $w.top.b insert end 1995
  70. # Use "tixSetSilent" to set the values of the combo box if you
  71. # don't want your -command procedures (cbx:select_month and
  72. # cbx:select_year) to be called.
  73. #
  74. tixSetSilent $w.top.a January
  75. tixSetSilent $w.top.b 1995
  76. # Use a ButtonBox to hold the buttons.
  77. #
  78. tixButtonBox $w.box -orientation horizontal
  79. $w.box add ok -text Ok -underline 0 -command "cbx:okcmd $w" \
  80. -width 6
  81. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  82. -width 6
  83. pack $w.box -side bottom -fill x
  84. pack $w.top -side top -fill both -expand yes
  85. }
  86. proc cbx:select_year {args} {
  87. tixDemo:Status "you have selected \"$args\""
  88. }
  89. proc cbx:select_month {s} {
  90. tixDemo:Status "you have selected \"$s\""
  91. }
  92. proc cbx:okcmd {w} {
  93. global demo_month demo_year
  94. tixDemo:Status "The month selected is $demo_month of $demo_year"
  95. destroy $w
  96. }
  97. if {![info exists tix_demo_running]} {
  98. wm withdraw .
  99. set w .demo
  100. toplevel $w; wm transient $w ""
  101. RunSample $w
  102. bind $w <Destroy> exit
  103. }
上海开阖软件有限公司 沪ICP备12045867号-1