When we talked about Listbox index values, each index referred to a line in the Listbox. The first line in the Listbox was at index 0, and so on. With a Text widget, the index can point to a specific line, but it can also point to a character within that line. An index for a Text widget is built using a base index and then optionally modifying that index. The entire index, base, and modifier should be put in double quotes.
Here is a list of base index values:
The index modifiers can be used following a base index value.
Here are some text index examples:
The basic indexes are easy. When you start doing index arithmetic, it becomes a little more complicated. Just remember that you are referring to a position in the Text widget that may change if other text is inserted or deleted (either by the user or the application).
Although some of the combinations may seem silly (e.g., '1.0 linestart'), keep in mind that you will most likely be calling methods that return indeterminate information about an event. For example, a user clicks in the Text widget and presses a Button that will increase the font size of that entire line. The index arithmetic allows you to reference that entire line without even knowing for sure which line it is on.
Copyright © 2002 O'Reilly & Associates. All rights reserved.