3
# Create a top-level window with a text widget that demonstrates the
4
# various display styles that are available in texts.
7
# w - Name to use for new top-level window.
9
proc mkStyles {{w .styles}} {
13
wm title $w "Text Demonstration - Display Styles"
14
wm iconname $w "Text Styles"
16
button $w.ok -text OK -command "destroy $w"
17
text $w.t -relief raised -bd 2 -yscrollcommand "$w.s set" -setgrid true \
19
scrollbar $w.s -relief flat -command "$w.t yview"
20
pack $w.ok -side bottom -fill x
21
pack $w.s -side right -fill y
22
pack $w.t -expand yes -fill both
24
# Set up display styles
26
$w.t tag configure bold -font -Adobe-Courier-Bold-O-Normal-*-120-*
27
$w.t tag configure big -font -Adobe-Courier-Bold-R-Normal-*-140-*
28
$w.t tag configure verybig -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
29
if {[tk colormodel $w] == "color"} {
30
$w.t tag configure color1 -background #eed5b7
31
$w.t tag configure color2 -foreground red
32
$w.t tag configure raised -background #eed5b7 -relief raised \
34
$w.t tag configure sunken -background #eed5b7 -relief sunken \
37
$w.t tag configure color1 -background black -foreground white
38
$w.t tag configure color2 -background black -foreground white
39
$w.t tag configure raised -background white -relief raised \
41
$w.t tag configure sunken -background white -relief sunken \
44
$w.t tag configure bgstipple -background black -borderwidth 0 \
46
$w.t tag configure fgstipple -fgstipple gray50
47
$w.t tag configure underline -underline on
50
Text widgets like this one allow you to display information in a
51
variety of styles. Display styles are controlled using a mechanism
53
insertWithTags $w.t tags bold
54
insertWithTags $w.t {. Tags are just textual names that you can apply to one
55
or more ranges of characters within a text widget. You can configure
56
tags with various display styles. If you do this, then the tagged
57
characters will be displayed with the styles you chose. The
58
available display styles are:
62
insertWithTags $w.t { You can choose any X font, }
63
insertWithTags $w.t large verybig
64
insertWithTags $w.t { or }
65
insertWithTags $w.t {small.
69
insertWithTags $w.t { You can change either the }
70
insertWithTags $w.t background color1
71
insertWithTags $w.t { or }
72
insertWithTags $w.t foreground color2
75
insertWithTags $w.t both color1 color2
76
insertWithTags $w.t {.
80
insertWithTags $w.t { You can cause either the }
81
insertWithTags $w.t background bgstipple
82
insertWithTags $w.t { or }
83
insertWithTags $w.t foreground fgstipple
85
information to be drawn with a stipple fill instead of a solid fill.
89
insertWithTags $w.t { You can }
90
insertWithTags $w.t underline underline
91
insertWithTags $w.t { ranges of text.
95
insertWithTags $w.t { You can arrange for the background to be drawn
96
with a border that makes characters appear either }
97
insertWithTags $w.t raised raised
98
insertWithTags $w.t { or }
99
insertWithTags $w.t sunken sunken
100
insertWithTags $w.t {.
102
insertWithTags $w.t {
104
insertWithTags $w.t { More display effects will be coming soon, such
105
as the ability to change line justification and perhaps line spacing.}
107
$w.t mark set insert 0.0
108
bind $w <Any-Enter> "focus $w.t"
111
# The procedure below inserts text into a given text widget and
112
# applies one or more tags to that text. The arguments are:
114
# w Window in which to insert
115
# text Text to insert (it's inserted at the "insert" mark)
116
# args One or more tags to apply to text. If this is empty
117
# then all tags are removed from the text.
119
proc insertWithTags {w text args} {
120
set start [$w index insert]
121
$w insert insert $text
122
foreach tag [$w tag names $start] {
123
$w tag remove $tag $start insert
126
$w tag add $i $start insert