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

3.1. The Button Widget

Of all of the widgets available with Perl/Tk, the button is one of the most commonly used. Just see all the examples in Chapter 2. When the button is pressed, something happens. That something can vary from exiting the program (as in our Hello World example) to beginning a longer series of operations such as opening a file or starting another process. The button typically displays a short text string: Done, Apply, Save, Ok, Exit.

Other widgets are also classified as buttons: radiobuttons, checkbuttons, and menubuttons. This chapter covers the traditional button. Chapter 4, and Chapter 11, will cover the other types because they look different on the screen and behave differently as well.

We cover the button widget first because it is easy to see the way different options affect it on the screen. Many of the other widgets included in Perl/Tk utilize the same options. Usually, if the option name is the same, the change to the widget will also be the same (more or less).

3.1.1. Creating a Button

The basic usage to create a button is as follows:

$button = $parentwidget->Button( [ option => value, . . . ] );

We have already seen examples of buttons in our Hello World program in Chapter 1, and in all the geometry management examples in Chapter 2. In these examples, a button is created and placed on the screen with a command like this:

$mw->Button(-text => "Done",-command ...
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