labelframe.tcl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # labelframe.tcl --
  2. #
  3. # This demonstration script creates a toplevel window containing
  4. # several labelframe 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 .labelframe
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Labelframe Demonstration"
  13. wm iconname $w "labelframe"
  14. positionWindow $w
  15. # Some information
  16. label $w.msg -font $font -wraplength 4i -justify left -text "Labelframes are\
  17. used to group related widgets together. The label may be either \
  18. plain text or another widget."
  19. pack $w.msg -side top
  20. ## See Code / Dismiss buttons
  21. set btns [addSeeDismiss $w.buttons $w]
  22. pack $btns -side bottom -fill x
  23. # Demo area
  24. frame $w.f
  25. pack $w.f -side bottom -fill both -expand 1
  26. set w $w.f
  27. # A group of radiobuttons in a labelframe
  28. labelframe $w.f -text "Value" -padx 2 -pady 2
  29. grid $w.f -row 0 -column 0 -pady 2m -padx 2m
  30. foreach value {1 2 3 4} {
  31. radiobutton $w.f.b$value -text "This is value $value" \
  32. -variable lfdummy -value $value
  33. pack $w.f.b$value -side top -fill x -pady 2
  34. }
  35. # Using a label window to control a group of options.
  36. proc lfEnableButtons {w} {
  37. foreach child [winfo children $w] {
  38. if {$child == "$w.cb"} continue
  39. if {$::lfdummy2} {
  40. $child configure -state normal
  41. } else {
  42. $child configure -state disabled
  43. }
  44. }
  45. }
  46. labelframe $w.f2 -pady 2 -padx 2
  47. checkbutton $w.f2.cb -text "Use this option." -variable lfdummy2 \
  48. -command "lfEnableButtons $w.f2" -padx 0
  49. $w.f2 configure -labelwidget $w.f2.cb
  50. grid $w.f2 -row 0 -column 1 -pady 2m -padx 2m
  51. set t 0
  52. foreach str {Option1 Option2 Option3} {
  53. checkbutton $w.f2.b$t -text $str
  54. pack $w.f2.b$t -side top -fill x -pady 2
  55. incr t
  56. }
  57. lfEnableButtons $w.f2
  58. grid columnconfigure $w {0 1} -weight 1