SListBox.tcl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: SListBox.tcl,v 1.4 2008/02/27 22:17:27 hobbs 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 tixScrolledListBox widget.
  13. #
  14. proc RunSample {w} {
  15. # We create the frame and the two ScrolledListBox widgets
  16. # at the top of the dialog box
  17. #
  18. frame $w.top -relief raised -bd 1
  19. # The first ScrolledListBox widget always shows both scrollbars
  20. #
  21. tixScrolledListBox $w.top.a -scrollbar both
  22. pack $w.top.a -expand yes -fill both -padx 10 -pady 10 -side left
  23. # The second ScrolledListBox widget shows the scrollbars only when
  24. # needed.
  25. #
  26. # [Hint] See how you can use the -options switch to set the options
  27. # for the subwidgets
  28. #
  29. tixScrolledListBox $w.top.b -scrollbar auto -options {
  30. listbox.font 8x13
  31. }
  32. pack $w.top.b -expand yes -fill both -padx 10 -pady 10 -side left
  33. # Put the elements inside the two listboxes: notice that you need
  34. # to insert inside the "listbox" subwidget of the ScrolledListBox.
  35. # $w.top.a itself does NOT have an "insert" command.
  36. #
  37. $w.top.a subwidget listbox insert 0 \
  38. Alabama Alaska Arizona Arkansas California \
  39. Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois \
  40. Indiana Iowa Kansas Kentucky Louisiana Maine Maryland \
  41. Massachusetts Michigan Minnesota Mississippi Missouri \
  42. Montana Nebraska Nevada "New Hampshire" "New Jersey" "New Mexico" \
  43. "New York" "North Carolina" "North Dakota" \
  44. Ohio Oklahoma Oregon Pennsylvania "Rhode Island" \
  45. "South Carolina" "South Dakota" \
  46. Tennessee Texas Utah Vermont Virginia Washington \
  47. "West Virginia" Wisconsin Wyoming
  48. raise [$w.top.a subwidget listbox ]
  49. $w.top.b subwidget listbox insert 0 \
  50. Alabama Alaska Arizona Arkansas California \
  51. Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois \
  52. Indiana Iowa Kansas Kentucky
  53. # Use a ButtonBox to hold the buttons.
  54. #
  55. tixButtonBox $w.box -orientation horizontal
  56. $w.box add ok -text Ok -underline 0 -command "destroy $w" \
  57. -width 6
  58. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  59. -width 6
  60. pack $w.box -side bottom -fill x
  61. pack $w.top -side top -fill both -expand yes
  62. }
  63. # This "if" statement makes it possible to run this script file inside or
  64. # outside of the main demo program "widget".
  65. #
  66. if {![info exists tix_demo_running]} {
  67. wm withdraw .
  68. set w .demo
  69. toplevel $w; wm transient $w ""
  70. RunSample $w
  71. bind $w <Destroy> exit
  72. }