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"
15 button $w.ok
-text OK
-command "destroy $w"
16 text $w.t
-relief raised
-bd 2 -yscrollcommand "$w.s set" -setgrid true
\
18 scrollbar $w.s
-relief flat
-command "$w.t yview"
19 pack append $w $w.ok
{bottom fillx
} $w.s
{right filly
} $w.t
{expand fill
}
21 # Set up display styles
23 $w.t tag configure bold
-font -Adobe-Courier
-Bold
-O
-Normal
-*-120-*
24 $w.t tag configure big
-font -Adobe-Courier
-Bold
-R
-Normal
-*-140-*
25 $w.t tag configure verybig
-font -Adobe-Helvetica
-Bold
-R
-Normal
-*-240-*
26 if {[winfo screendepth
$w] > 4} {
27 $w.t tag configure color1
-background #eed5b7
28 $w.t tag configure color2
-foreground red
29 $w.t tag configure raised
-background #eed5b7 -relief raised \
31 $w.t tag configure sunken
-background #eed5b7 -relief sunken \
34 $w.t tag configure color1
-background black
-foreground white
35 $w.t tag configure color2
-background black
-foreground white
36 $w.t tag configure raised
-background white
-relief raised
\
38 $w.t tag configure sunken
-background white
-relief sunken
\
41 $w.t tag configure bgstipple
-background black
-borderwidth 0 \
43 $w.t tag configure fgstipple
-fgstipple gray50
44 $w.t tag configure underline
-underline on
47 Text widgets like this one allow you to display information in a
48 variety of styles. Display styles are controlled using a mechanism
50 insertWithTags
$w.t tags bold
51 insertWithTags
$w.t
{. Tags are just textual names that you can apply to one
52 or more ranges of characters within a
text widget. You can configure
53 tags with various display styles. If you do this
, then the tagged
54 characters will be displayed with the styles you chose. The
55 available display styles are
:
59 insertWithTags
$w.t
{ You can choose any X
font, }
60 insertWithTags
$w.t large verybig
61 insertWithTags
$w.t
{ or
}
62 insertWithTags
$w.t
{small.
66 insertWithTags
$w.t
{ You can change either the
}
67 insertWithTags
$w.t background color1
68 insertWithTags
$w.t
{ or
}
69 insertWithTags
$w.t foreground color2
72 insertWithTags
$w.t both color1 color2
73 insertWithTags
$w.t
{.
77 insertWithTags
$w.t
{ You can cause either the
}
78 insertWithTags
$w.t background bgstipple
79 insertWithTags
$w.t
{ or
}
80 insertWithTags
$w.t foreground fgstipple
82 information to be drawn with a stipple fill instead of a solid fill.
86 insertWithTags
$w.t
{ You can
}
87 insertWithTags
$w.t underline underline
88 insertWithTags
$w.t
{ ranges of
text.
92 insertWithTags
$w.t
{ You can arrange
for the background to be drawn
93 with a border that makes characters appear either
}
94 insertWithTags
$w.t raised raised
95 insertWithTags
$w.t
{ or
}
96 insertWithTags
$w.t sunken sunken
97 insertWithTags
$w.t
{.
101 insertWithTags
$w.t
{ More display effects will be coming soon
, such
102 as the ability to change line justification and perhaps line spacing.
}
104 $w.t mark
set insert
0.0
105 bind $w <Any-Enter
> "focus $w.t"
108 # The procedure below inserts text into a given text widget and
109 # applies one or more tags to that text. The arguments are:
111 # w Window in which to insert
112 # text Text to insert (it's inserted at the "insert" mark)
113 # args One or more tags to apply to text. If this is empty
114 # then all tags are removed from the text.
116 proc insertWithTags
{w
text args
} {
117 set start
[$w index insert
]
118 $w insert insert
$text
119 foreach tag
[$w tag names
$start] {
120 $w tag remove
$tag $start insert
123 $w tag add
$i $start insert