Chapter 13. Toplevel Widgets

Any Perl/Tk application includes at least one toplevel widget. When you call the new method from the MainWindow class, you are creating a toplevel widget without even knowing it. You can create other toplevel widgets to be used in your application in addition to the MainWindow toplevel widget. The MainWindow is special because it automatically displays when you call MainLoop(). Other toplevel widgets in your program must be explicitly displayed somewhere in the code.

Here are some examples of how you can use toplevel widgets:

  • Display informational text with a Close button. [1]

    [1] Look at Tk::Dialog. It is designed to do this and uses a toplevel widget.

  • Provide data gathering that is triggered by something the user does (for example, clicking a button).

All toplevel widgets have the same behavior: Each has decoration that is consistent with the system on which your application is run. Each toplevel can contain other widgets and/or multiple groups of widgets (for example, they can be grouped in a frame widget).

The rest of the chapter will cover how to use toplevel widgets and what options allow you to change their behavior.

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.