Next / Previous / Contents / TCC Help System / NM Tech homepage

17.1. Indices in text widgets

An index is a general method of specifying a position in the content of a text widget. An index is a string with one of these forms:

"line.column"

The position just before the given column (counting from zero) on the given line (counting from one). Examples: "1.0" is the position of the beginning of the text; "2.3" is the position before the fourth character of the second line.

"line.end"

The position just before the newline at the end of the given line (counting from one). So, for example, index "10.end" is the position at the end of the tenth line.

INSERT

The position of the insertion cursor in the text widget.

CURRENT

The position of the character closest to the mouse pointer.

END

The position after the last character of the text.

SEL_FIRST

If some of the text in the widget is currently selection (as by dragging the mouse over it), this is the position before the start of the selection. If you try to use this index and nothing is selected, a TclError exception will be raised.

SEL_LAST

The position after the end of the selection, if any. As with SEL_FIRST, you'll get a TclError exception if you use such an index and there is no selection.

"markname"

You can use a mark as an index; just pass its name where an index is expected. See Section 17.2, “Marks in text widgets”.

"tag.first"

The position before the first character of the region tagged with name tag; see Section 17.5, “Tags in text widgets”.

"tag.last"

The position after the last character of a tagged region.

"@x,y"

The position before the character closest to the coordinate (x, y).

embedded-object

If you have an image or window embedded in the text widget, you can use the PhotoImage, BitmapImage, or embedded widget as an index. See Section 17.3, “Images in text widgets” and Section 17.4, “Windows in text widgets”.