Create a Text widget with the Text method:
$parentwidget->Text ( options)
The standard configuration options that apply to Text are: -background, -bg, -bor-derwidth, -bd, -cursor, -exportselection, -font, -foreground, -fg, -height, -high-lightbackground, -highlightcolor, -highlightthickness, -insertbackground, -in-sertborderwidth, -insertofftime, -insertontime, -insertwidth, -padx, -pady, -re-lief, -selectbackground, -selectborderwidth, -selectforeground, -state, -takefo-cus, -width, -xscrollcommand, and -yscrollcommand.
Other options are:
In a Text widget, several indexes are defined to identify positions in the text. These are used by the methods that retrieve and manipulate text.
There are also several modifiers to use with text indexes. They are:
In addition to configure and cget, the following methods are defined for the Text widget:
if ($text->compare('insert', '==', 'end') { # we're at the end of the text }
The valid operators are <, <=, ==, >=, and !=.
$text->delete(0, 'end');
$text->insert('end', 'You want to do ', 'normal', 'what?!', ['bold','red']);
$hostindex = $text->search(-nocase, -backwards, $hostname, 'end');
The search method takes several switches to modify the search, each starting with -. The first argument that does not start with - is taken to be the search string. The switches are:
$button = $text->Label(-text => "How ya doing?"); $text->window('create','end', -window => $button);
Here, the -window option is used to identify the widget to embed. The list of options to window ('create') is:
$text->window('cget',0);
$text->window('configure',0,-background => "green");
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:
$text->tagAdd('bold','sel.first','sel.last');
You can supply multiple ranges as arguments to tagAdd.
$text->tagBind('goto_end', "<Button-1>", sub {shift->see('end');} );
$text->tagConfigure('link', -foreground => 'red');
Options for configuring text tags are:
$text->tagRaise('bold','italic');
$text->tagLower('italic','bold');
@defined_tags = $text->tagNames;
@bold_indexes = $text->tagRanges('bold');
@next_bold = $text->tagRanges('bold', 'insert');
A mark is a particular position between characters in a Text widget. Once you create a mark, you can use it as an index. The gravity of the mark affects to 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:
$text->markGravity('insert', 'left');
$text->markSet('saved', 'insert');
$text->markUnset('saved');
Note that you cannot delete the insert or current marks.
Copyright © 2002 O'Reilly & Associates. All rights reserved.