Chapter 8. The Text Widget

When you think about what a text widget might do, you automatically think, "it displays text." This is true, yet it can do quite a bit more. The text widget is one of the most powerful standard widgets available in Perl/Tk. It is flexible, configurable, and easy to use for simple tasks. Here are some examples of how you can use text widgets:

  • Display and edit a plain text file.

  • Display formatted text from an HTML document.

  • Create a scrollable color key, with buttons that allow you change the colors

  • Gather multiline, formatted text (including colors) from a user (mini word processor).

  • Display text with different colors based on the input.

  • Make certain portions of text "clickable" and perform an action when clicked on. This could be HTML, or it could be similar to the widget demo.[1]

    [1] When you installed the Tk module with Perl, you also installed the widget demo. Type widget on the command line to see the capabilities of widgets in Perl/Tk.

You can put simple text, formatted text, and other widgets inside a text widget. A text widget can be used in conjunction with scrollbars to allow many pages of information to be viewed in much less space.

Get Learning Perl/Tk 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.