ttkpane.tcl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # ttkpane.tcl --
  2. #
  3. # This demonstration script creates a Ttk pane with some content.
  4. if {![info exists widgetDemo]} {
  5. error "This script should be run from the \"widget\" demo."
  6. }
  7. package require Tk
  8. package require Ttk
  9. set w .ttkpane
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Themed Nested Panes"
  13. wm iconname $w "ttkpane"
  14. positionWindow $w
  15. ttk::label $w.msg -font $font -wraplength 4i -justify left -text "This demonstration shows off a nested set of themed paned windows. Their sizes can be changed by grabbing the area between each contained pane and dragging the divider."
  16. pack $w.msg [ttk::separator $w.msgSep] -side top -fill x
  17. ## See Code / Dismiss
  18. pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x
  19. ttk::frame $w.f
  20. pack $w.f -fill both -expand 1
  21. set w $w.f
  22. ttk::panedwindow $w.outer -orient horizontal
  23. $w.outer add [ttk::panedwindow $w.outer.inLeft -orient vertical]
  24. $w.outer add [ttk::panedwindow $w.outer.inRight -orient vertical]
  25. $w.outer.inLeft add [ttk::labelframe $w.outer.inLeft.top -text Button]
  26. $w.outer.inLeft add [ttk::labelframe $w.outer.inLeft.bot -text Clocks]
  27. $w.outer.inRight add [ttk::labelframe $w.outer.inRight.top -text Progress]
  28. $w.outer.inRight add [ttk::labelframe $w.outer.inRight.bot -text Text]
  29. if {[tk windowingsystem] eq "aqua"} {
  30. foreach i [list inLeft.top inLeft.bot inRight.top inRight.bot] {
  31. $w.outer.$i configure -padding 3
  32. }
  33. }
  34. # Fill the button pane
  35. ttk::button $w.outer.inLeft.top.b -text "Press Me" -command {
  36. tk_messageBox -type ok -icon info -message "Ouch!" -detail "That hurt..." \
  37. -parent .ttkpane -title "Button Pressed"
  38. }
  39. pack $w.outer.inLeft.top.b -padx 2 -pady 5
  40. # Fill the clocks pane
  41. set i 0
  42. proc every {delay script} {
  43. uplevel #0 $script
  44. after $delay [list every $delay $script]
  45. }
  46. set zones {
  47. :Europe/Berlin
  48. :America/Argentina/Buenos_Aires
  49. :Africa/Johannesburg
  50. :Europe/London
  51. :America/Los_Angeles
  52. :Europe/Moscow
  53. :America/New_York
  54. :Asia/Singapore
  55. :Australia/Sydney
  56. :Asia/Tokyo
  57. }
  58. # Force a pre-load of all the timezones needed; otherwise can end up
  59. # poor-looking synch problems!
  60. foreach zone $zones {clock format 0 -timezone $zone}
  61. foreach zone $zones {
  62. set city [string map {_ " "} [regexp -inline {[^/]+$} $zone]]
  63. if {$i} {
  64. pack [ttk::separator $w.outer.inLeft.bot.s$i] -fill x
  65. }
  66. ttk::label $w.outer.inLeft.bot.l$i -text $city -anchor w
  67. ttk::label $w.outer.inLeft.bot.t$i -textvariable time($zone) -anchor w
  68. pack $w.outer.inLeft.bot.l$i $w.outer.inLeft.bot.t$i -fill x
  69. every 1000 "set time($zone) \[clock format \[clock seconds\] -timezone $zone -format %T\]"
  70. incr i
  71. }
  72. # Fill the progress pane
  73. ttk::progressbar $w.outer.inRight.top.progress -mode indeterminate
  74. pack $w.outer.inRight.top.progress -fill both -expand 1
  75. $w.outer.inRight.top.progress start
  76. # Fill the text pane
  77. if {[tk windowingsystem] ne "aqua"} {
  78. # The trick with the ttk::frame makes the text widget look like it fits with
  79. # the current Ttk theme despite not being a themed widget itself. It is done
  80. # by styling the frame like an entry, turning off the border in the text
  81. # widget, and putting the text widget in the frame with enough space to allow
  82. # the surrounding border to show through (2 pixels seems to be enough).
  83. ttk::frame $w.outer.inRight.bot.f -style TEntry
  84. text $w.txt -wrap word -yscroll "$w.sb set" -width 30 -borderwidth 0
  85. pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot.f -pady 2 -padx 2
  86. ttk::scrollbar $w.sb -orient vertical -command "$w.txt yview"
  87. pack $w.sb -side right -fill y -in $w.outer.inRight.bot
  88. pack $w.outer.inRight.bot.f -fill both -expand 1
  89. pack $w.outer -fill both -expand 1
  90. } else {
  91. text $w.txt -wrap word -yscroll "$w.sb set" -width 30 -borderwidth 0
  92. scrollbar $w.sb -orient vertical -command "$w.txt yview"
  93. pack $w.sb -side right -fill y -in $w.outer.inRight.bot
  94. pack $w.txt -fill both -expand 1 -in $w.outer.inRight.bot
  95. pack $w.outer -fill both -expand 1 -padx 10 -pady {6 10}
  96. }