O'Reilly logo

Learning Perl/Tk by Nancy Walsh

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

8.5. Text Tags

Text tags give you another way to address portions of text in the text widget. A tag has three purposes, and the same tag can serve all three or only one:

  • Assigning formatting information to a portion(s) of text

  • Associating a binding with text in the widget

  • Managing selected text

Tags are also used to change how the text appears on the screen: font, size, coloring, and spacing are among a few of the text properties affected by tags. You change text properties by creating your own tags (with their own names), and using option/value pairs to assign formatting information. In addition to changing the formatting, you can use a tag to apply a specific binding (such as perform a task when the user clicks on that text). A special tag "sel" manages the selected text. Anytime the user selects some text, the location of that text is marked with the tag "sel".

Any of the text within the text widget can have one or more tags associated with it. If you apply two tags to the same piece of text and they both alter the font, the last tag applied wins.

8.5.1. Options Used With Tags

The options you can use to configure tagged text are mostly a subset of the configuration options of the text widget itself. There are some options that can only be used through tagged text.

-background => color

Sets the color of the area behind the text.

-bgstipple => pattern

Sets the pattern used to draw the area behind the text. Can create a shaded look.

-borderwidth => amount

Sets the width of ...

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