Marks
There are several ways to refer to
different positions throughout the Text widget. An index value refers
to a character. A tag is a named reference to a specific character or
group of characters. The term mark
refers to the
spaces between characters. Similar to tags, a mark has a name. For
example, the "insert"
mark refers to the position
of the insert cursor. However, tags refer to the actual characters,
and if those characters are deleted, the tag is no longer associated
with those characters. The mark stays in place whether the characters
surrounding it are deleted or other characters are added. Marks can
refer only to one location within the Text widget at a time.
Once a mark is created, you can use it as
an index. The gravity of the mark will determine if the mark moves or
not when you insert text with it. Using a gravity of
'right'
(the default) means that any text inserted
using that mark will go to the left of the mark. A gravity of
'left'
means that text inserted using that mark
will go to the right of the mark. Another way to think about it is
the gravity tells you which side the mark will stick to. For example,
suppose we have the string "abcdef"
and place the
mark in between the c
and the
d
. We’ll represent the mark as a
^
character. Using 'right'
gravity, "abc^def"
becomes
"abc1232^def"
because the mark sticks to the
character to its right. Using 'left'
gravity,
"abc^def"
becomes "abc^123def"
because the mark sticks to the character to its left. ...
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.