Next / Previous / Contents

24.2. Text widget marks

A mark represents a floating position somewhere in the contents of a text widget.

  • You handle each mark by giving it a name. This name can be any string that doesn't include whitespace or periods.

  • There are two special marks. tk.INSERT is the current position of the insertion cursor, and tk.CURRENT is the position closest to the mouse cursor.

  • Marks float along with the adjacent content. If you modify text somewhere away from a mark, the mark stays at the same position relative to its immediate neighbors.

  • Marks have a property called gravity that controls what happens when you insert text at a mark. The default gravity is tk.RIGHT, which means that when new text is inserted at that mark, the mark stays after the end of the new text. If you set the gravity of a mark to tk.LEFT (using the text widget's .mark_gravity() method), the mark will stay at a position just before text newly inserted at that mark.

  • Deleting the text all around a mark does not remove the mark. If you want to remove a mark, use the .mark_unset() method on the text widget.

Refer to Section 24.8, “Methods on Text widgets”, below, to see how to use marks.