paned2.tcl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # paned2.tcl --
  2. #
  3. # This demonstration script creates a toplevel window containing
  4. # a paned window that separates two windows vertically.
  5. if {![info exists widgetDemo]} {
  6. error "This script should be run from the \"widget\" demo."
  7. }
  8. package require Tk
  9. set w .paned2
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Vertical Paned Window Demonstration"
  13. wm iconname $w "paned2"
  14. positionWindow $w
  15. label $w.msg -font $font -wraplength 4i -justify left -text "The sash between the two scrolled windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)"
  16. pack $w.msg -side top
  17. ## See Code / Dismiss buttons
  18. set btns [addSeeDismiss $w.buttons $w]
  19. pack $btns -side bottom -fill x
  20. # Create the pane itself
  21. panedwindow $w.pane -orient vertical
  22. pack $w.pane -side top -expand yes -fill both -pady 2 -padx 2m
  23. # The top window is a listbox with scrollbar
  24. set paneList {
  25. {List of Tk Widgets}
  26. button
  27. canvas
  28. checkbutton
  29. entry
  30. frame
  31. label
  32. labelframe
  33. listbox
  34. menu
  35. menubutton
  36. message
  37. panedwindow
  38. radiobutton
  39. scale
  40. scrollbar
  41. spinbox
  42. text
  43. toplevel
  44. }
  45. set f [frame $w.pane.top]
  46. listbox $f.list -listvariable paneList -yscrollcommand "$f.scr set"
  47. # Invert the first item to highlight it
  48. $f.list itemconfigure 0 \
  49. -background [$f.list cget -fg] -foreground [$f.list cget -bg]
  50. ttk::scrollbar $f.scr -orient vertical -command "$f.list yview"
  51. pack $f.scr -side right -fill y
  52. pack $f.list -fill both -expand 1
  53. # The bottom window is a text widget with scrollbar
  54. set f [frame $w.pane.bottom]
  55. text $f.text -xscrollcommand "$f.xscr set" -yscrollcommand "$f.yscr set" \
  56. -width 30 -height 8 -wrap none
  57. ttk::scrollbar $f.xscr -orient horizontal -command "$f.text xview"
  58. ttk::scrollbar $f.yscr -orient vertical -command "$f.text yview"
  59. grid $f.text $f.yscr -sticky nsew
  60. grid $f.xscr -sticky nsew
  61. grid columnconfigure $f 0 -weight 1
  62. grid rowconfigure $f 0 -weight 1
  63. $f.text insert 1.0 "This is just a normal text widget"
  64. # Now add our contents to the paned window
  65. $w.pane add $w.pane.top $w.pane.bottom