Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

1.8. Displaying a Widget

You use two separate commands to create a widget and display it, although sometimes they are squished into the same line, which makes them look like the same command. In the examples so far, we've used the Button method to create the button, but nothing is displayed by using that method alone. Instead you have to use a geometry manager to cause the widget to be displayed in its parent widget or in another widget. The most commonly used geometry manager is pack, and to use it, you simply call the pack() method on the widget object like this:

$widget->pack();

For example:

$button->pack();

There are arguments that can be sent to the pack method, but we'll cover those in Chapter 2.

It is not necessary to invoke the pack method on a separate line. The ->pack can be added to the creation of the widget:

$parent->Button(-text => "Bye!", -command => sub { exit })->pack();

The other geometry managers available are grid and place. All three behave differently, and which one you use often depends on the look you are trying to get in your application. Again, look for information on the geometry managers in Chapter 2.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata