radio.tcl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # radio.tcl --
  2. #
  3. # This demonstration script creates a toplevel window containing
  4. # several radiobutton widgets.
  5. if {![info exists widgetDemo]} {
  6. error "This script should be run from the \"widget\" demo."
  7. }
  8. package require Tk
  9. set w .radio
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Radiobutton Demonstration"
  13. wm iconname $w "radio"
  14. positionWindow $w
  15. label $w.msg -font $font -wraplength 5i -justify left -text "Three groups of radiobuttons are displayed below. If you click on a button then the button will become selected exclusively among all the buttons in its group. A Tcl variable is associated with each group to indicate which of the group's buttons is selected. When the 'Tristate' button is pressed, the radio buttons will display the tri-state mode. Selecting any radio button will return the buttons to their respective on/off state. Click the \"See Variables\" button to see the current values of the variables."
  16. grid $w.msg -row 0 -column 0 -columnspan 3 -sticky nsew
  17. ## See Code / Dismiss buttons
  18. set btns [addSeeDismiss $w.buttons $w [list size color align]]
  19. grid $btns -row 3 -column 0 -columnspan 3 -sticky ew
  20. labelframe $w.left -pady 2 -text "Point Size" -padx 2
  21. labelframe $w.mid -pady 2 -text "Color" -padx 2
  22. labelframe $w.right -pady 2 -text "Alignment" -padx 2
  23. button $w.tristate -text Tristate -command "set size multi; set color multi" \
  24. -pady 2 -padx 2
  25. if {[tk windowingsystem] eq "aqua"} {
  26. $w.tristate configure -padx 10
  27. }
  28. grid $w.left -column 0 -row 1 -pady .5c -padx .5c -rowspan 2
  29. grid $w.mid -column 1 -row 1 -pady .5c -padx .5c -rowspan 2
  30. grid $w.right -column 2 -row 1 -pady .5c -padx .5c
  31. grid $w.tristate -column 2 -row 2 -pady .5c -padx .5c
  32. foreach i {10 12 14 18 24} {
  33. radiobutton $w.left.b$i -text "Point Size $i" -variable size \
  34. -relief flat -value $i -tristatevalue "multi"
  35. pack $w.left.b$i -side top -pady 2 -anchor w -fill x
  36. }
  37. foreach c {Red Green Blue Yellow Orange Purple} {
  38. set lower [string tolower $c]
  39. radiobutton $w.mid.$lower -text $c -variable color \
  40. -relief flat -value $lower -anchor w \
  41. -command "$w.mid configure -fg \$color" \
  42. -tristatevalue "multi"
  43. pack $w.mid.$lower -side top -pady 2 -fill x
  44. }
  45. label $w.right.l -text "Label" -bitmap questhead -compound left
  46. $w.right.l configure -width [winfo reqwidth $w.right.l] -compound top
  47. $w.right.l configure -height [winfo reqheight $w.right.l]
  48. foreach a {Top Left Right Bottom} {
  49. set lower [string tolower $a]
  50. radiobutton $w.right.$lower -text $a -variable align \
  51. -relief flat -value $lower -indicatoron 0 -width 7 \
  52. -command "$w.right.l configure -compound \$align"
  53. }
  54. grid x $w.right.top
  55. grid $w.right.left $w.right.l $w.right.right
  56. grid x $w.right.bottom