Text Methods

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

bbox

Returns the location and dimensions of the bounding box surrounding the character at the specified index. The returned list contains four numbers representing (respectively) the x coordinate of the upper-left corner, the y coordinate of the upper-left corner, the width of the text in pixels, and the height of the text in pixels.

compare

Performs a comparison on two indexes. For example:

if ($text->compare('insert', '==', 'end') { 
        # we're at the end of the text
}

The valid operators are <, <=, ==, >=, and !=.

debug

Given a Boolean, turns debugging on or off.

delete

Deletes text from the text widget. To delete everything:

$text->delete(0, 'end');
dlineinfo

Returns the location and dimensions of the bounding box surrounding the line at the specified index. The returned list contains five numbers representing (respectively) the x coordinate of the upper-left corner, the y coordinate of the upper-left corner, the width of the text in pixels, the height of the text in pixels, and the baseline position of the line.

get

Returns the text located in the given index range.

index

Given a named index, returns its numeric equivalent in the format line.char.

insert

Inserts text into the widget at the specified location. The second argument is the text to insert, and the third argument is either a single tag or a list reference containing the names of multiple tags to apply to the text. Subsequent arguments ...

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.