The Text Widget

Create a text widget with the Text method:

$parentwidget->Text ( options)


The standard configuration options that apply to Text are: -background, -bg, -borderwidth, -bd, -cursor, -exportselection, -font, -foreground, -fg, -height, -highlightbackground, -highlightcolor, -highlightthickness, -insertbackground, -insertborderwidth, -insertofftime, -insertontime, -insertwidth, -padx, -pady, -relief, -selectbackground, -selectborderwidth, -selectforeground, -state, -takefocus, -width, -xscrollcommand, and -yscrollcommand.

Other options are:

Text Indexes and Modifiers

In a Text widget, several indexes are defined to identify positions in the text widget, for use by the methods used for retrieving or manipulating text. These indexes are:

There are also several modifiers to use with text indexes. They are:

Text Methods

In addition to configure and cget, the following methods are defined for the Text widget.

Tags

You can associate a distinct set of format properties to a portion of the text using tags. A tag is defined with the tagConfigure method, and text is associated with a tag via an option to the insert or tagAdd method. For example:

$text->Text->pack; $text->tagConfigure('bold', -font => '-*-Courier-Medium-B-Normal-*-120-*-*-*-*-*-*"); $text->insert('end', "Normal text\n"); $text->insert('end', "Bold text\n", 'bold');


There are several methods defined for manipulating text tags. They are:

Marks

A mark refers to a particular position in between characters in a text widget. Once you create a mark, you can use it as an index. The gravity of the mark affects which side the text is inserted. "Right" gravity is the default, in which case the text is inserted to the right of the mark.

The two marks that are automatically set are "insert" and "current". The "insert" mark refers to the position of the insert cursor. The "current" mark is the position closest to the mouse cursor.

The following methods are defined for marking:

Note that you cannot delete the "insert" or "current" marks.