There are lots of ways to change both the appearance and functionality of the items in a text widget. For text, you can change the font, size, and color. Also, you can make text, widgets, or embedded images respond to keyboard or mouse actions.
To control these appearance and functional features, you associate each feature with a tag. You can then associate a tag with any number of pieces of text in the widget.
The name of a tag can be any string that does not contain white space or periods.
There is one special predefined tag called
SEL
. This is the region
currently selected, if any.
Since any character may be part of more than one tag, there is a tag stack that orders all the tags. Entries are added at the end of the tag list, and later entries have priority over earlier entries.
So, for example, if there is a character
c
that is part of two
tagged regions
t1
and
t2
,
and
t1
is deeper in the tag stack than
t2
,
and
t1
wants the text to be green and
t2
wants it to be blue, c
will be rendered in blue because
t2
has precedence over
t1
.
You can change the ordering of tags in the tag stack.
Tags are created by using the
.tag_add()
method on the text
widget. See Section 17.7, “Methods on Text
widgets”, below, for
information on this and related methods.