8.16. Marks

There are several ways to refer to different positions throughout the text widget. Index values refer to a character. Tags are named references to a specific character or characters. The term mark is used to refer to the spaces in 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 only refer to one location within the text widget at a time.

Once it is created, you can use a mark as an index. The gravity of the mark will affect on which side the text will be inserted. If the gravity is 'right' (the default), the text will be inserted to the left of the mark because the mark is glued to the character to the right of the mark. If the gravity is 'left', the text will be inserted to the left of the mark and the mark will refer to the left of the last character inserted.

There are two special marks that are set automatically by the text widget: "insert"and "current". The "insert" mark is wherever the insert cursor is. The "current" mark is the position closest to the mouse and adjusts as the mouse moves (as long as a mouse button is pressed). Both marks are maintained internally and cannot be deleted.

You will also see a mark called "anchor"

Get Learning 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.