O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Looking inside the Text Widget

The text widget has several operations that let you examine its contents. The simplest is get, which returns a range of text from the widget. You can get all the text with this command:

$t get 1.0 end

Looking at Tags

The tag names command returns all the tag names, or the names of the tags at a specified index:

$t tag names ?index?

A text tag can be applied to many different ranges of text. The tag ranges operation returns a list of indices that alternate between the start and end of tag ranges. The foreach command with two loop variables makes it easy to iterate through all the ranges:

foreach {start end}[$t tag ranges $tag] {
   # start is the beginning of a range
   # end is the end of a range
}

The tag nextrange ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required