style.tcl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # style.tcl --
  2. #
  3. # This demonstration script creates a text widget that illustrates the
  4. # various display styles that may be set for tags.
  5. if {![info exists widgetDemo]} {
  6. error "This script should be run from the \"widget\" demo."
  7. }
  8. package require Tk
  9. set w .style
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Text Demonstration - Display Styles"
  13. wm iconname $w "style"
  14. positionWindow $w
  15. ## See Code / Dismiss buttons
  16. set btns [addSeeDismiss $w.buttons $w]
  17. pack $btns -side bottom -fill x
  18. # Only set the font family in one place for simplicity and consistency
  19. set family Courier
  20. text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
  21. -width 70 -height 32 -wrap word -font "$family 12"
  22. ttk::scrollbar $w.scroll -command "$w.text yview"
  23. pack $w.scroll -side right -fill y
  24. pack $w.text -expand yes -fill both
  25. # Set up display styles
  26. $w.text tag configure bold -font "$family 12 bold italic"
  27. $w.text tag configure big -font "$family 14 bold"
  28. $w.text tag configure verybig -font "Helvetica 24 bold"
  29. $w.text tag configure tiny -font "Times 8 bold"
  30. if {[winfo depth $w] > 1} {
  31. $w.text tag configure color1 -background #a0b7ce
  32. $w.text tag configure color2 -foreground red
  33. $w.text tag configure raised -relief raised -borderwidth 1
  34. $w.text tag configure sunken -relief sunken -borderwidth 1
  35. } else {
  36. $w.text tag configure color1 -background black -foreground white
  37. $w.text tag configure color2 -background black -foreground white
  38. $w.text tag configure raised -background white -relief raised \
  39. -borderwidth 1
  40. $w.text tag configure sunken -background white -relief sunken \
  41. -borderwidth 1
  42. }
  43. $w.text tag configure bgstipple -background black -borderwidth 0 \
  44. -bgstipple gray12
  45. $w.text tag configure fgstipple -fgstipple gray50
  46. $w.text tag configure underline -underline on
  47. $w.text tag configure overstrike -overstrike on
  48. $w.text tag configure right -justify right
  49. $w.text tag configure center -justify center
  50. $w.text tag configure super -offset 4p -font "$family 10"
  51. $w.text tag configure sub -offset -2p -font "$family 10"
  52. $w.text tag configure margins -lmargin1 12m -lmargin2 6m -rmargin 10m
  53. $w.text tag configure spacing -spacing1 10p -spacing2 2p \
  54. -lmargin1 12m -lmargin2 6m -rmargin 10m
  55. $w.text insert end {Text widgets like this one allow you to display information in a
  56. variety of styles. Display styles are controlled using a mechanism
  57. called }
  58. $w.text insert end tags bold
  59. $w.text insert end {. Tags are just textual names that you can apply to one
  60. or more ranges of characters within a text widget. You can configure
  61. tags with various display styles. If you do this, then the tagged
  62. characters will be displayed with the styles you chose. The
  63. available display styles are:
  64. }
  65. $w.text insert end "\n1. Font." big
  66. $w.text insert end " You can choose any system font, "
  67. $w.text insert end large verybig
  68. $w.text insert end " or "
  69. $w.text insert end "small" tiny ".\n"
  70. $w.text insert end "\n2. Color." big
  71. $w.text insert end " You can change either the "
  72. $w.text insert end background color1
  73. $w.text insert end " or "
  74. $w.text insert end foreground color2
  75. $w.text insert end "\ncolor, or "
  76. $w.text insert end both {color1 color2}
  77. $w.text insert end ".\n"
  78. $w.text insert end "\n3. Stippling." big
  79. $w.text insert end " You can cause either the "
  80. $w.text insert end background bgstipple
  81. $w.text insert end " or "
  82. $w.text insert end foreground fgstipple
  83. $w.text insert end {
  84. information to be drawn with a stipple fill instead of a solid fill.
  85. }
  86. $w.text insert end "\n4. Underlining." big
  87. $w.text insert end " You can "
  88. $w.text insert end underline underline
  89. $w.text insert end " ranges of text.\n"
  90. $w.text insert end "\n5. Overstrikes." big
  91. $w.text insert end " You can "
  92. $w.text insert end "draw lines through" overstrike
  93. $w.text insert end " ranges of text.\n"
  94. $w.text insert end "\n6. 3-D effects." big
  95. $w.text insert end { You can arrange for the background to be drawn
  96. with a border that makes characters appear either }
  97. $w.text insert end raised raised
  98. $w.text insert end " or "
  99. $w.text insert end sunken sunken
  100. $w.text insert end ".\n"
  101. $w.text insert end "\n7. Justification." big
  102. $w.text insert end " You can arrange for lines to be displayed\n"
  103. $w.text insert end "left-justified,\n"
  104. $w.text insert end "right-justified, or\n" right
  105. $w.text insert end "centered.\n" center
  106. $w.text insert end "\n8. Superscripts and subscripts." big
  107. $w.text insert end " You can control the vertical\n"
  108. $w.text insert end "position of text to generate superscript effects like 10"
  109. $w.text insert end "n" super
  110. $w.text insert end " or\nsubscript effects like X"
  111. $w.text insert end "i" sub
  112. $w.text insert end ".\n"
  113. $w.text insert end "\n9. Margins." big
  114. $w.text insert end " You can control the amount of extra space left"
  115. $w.text insert end " on\neach side of the text:\n"
  116. $w.text insert end "This paragraph is an example of the use of " margins
  117. $w.text insert end "margins. It consists of a single line of text " margins
  118. $w.text insert end "that wraps around on the screen. There are two " margins
  119. $w.text insert end "separate left margin values, one for the first " margins
  120. $w.text insert end "display line associated with the text line, " margins
  121. $w.text insert end "and one for the subsequent display lines, which " margins
  122. $w.text insert end "occur because of wrapping. There is also a " margins
  123. $w.text insert end "separate specification for the right margin, " margins
  124. $w.text insert end "which is used to choose wrap points for lines.\n" margins
  125. $w.text insert end "\n10. Spacing." big
  126. $w.text insert end " You can control the spacing of lines with three\n"
  127. $w.text insert end "separate parameters. \"Spacing1\" tells how much "
  128. $w.text insert end "extra space to leave\nabove a line, \"spacing3\" "
  129. $w.text insert end "tells how much space to leave below a line,\nand "
  130. $w.text insert end "if a text line wraps, \"spacing2\" tells how much "
  131. $w.text insert end "space to leave\nbetween the display lines that "
  132. $w.text insert end "make up the text line.\n"
  133. $w.text insert end "These indented paragraphs illustrate how spacing " spacing
  134. $w.text insert end "can be used. Each paragraph is actually a " spacing
  135. $w.text insert end "single line in the text widget, which is " spacing
  136. $w.text insert end "word-wrapped by the widget.\n" spacing
  137. $w.text insert end "Spacing1 is set to 10 points for this text, " spacing
  138. $w.text insert end "which results in relatively large gaps between " spacing
  139. $w.text insert end "the paragraphs. Spacing2 is set to 2 points, " spacing
  140. $w.text insert end "which results in just a bit of extra space " spacing
  141. $w.text insert end "within a pararaph. Spacing3 isn't used " spacing
  142. $w.text insert end "in this example.\n" spacing
  143. $w.text insert end "To see where the space is, select ranges of " spacing
  144. $w.text insert end "text within these paragraphs. The selection " spacing
  145. $w.text insert end "highlight will cover the extra space." spacing