Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: 18.3 Common Widget Configuration OptionsChapter 18
Next: 18.5 The Checkbutton Widget

18.4 The Button Widget

Create a simple button with the Button method:

$parentwidget->Button (options)
The standard configuration options that apply to Button are: -activebackground, -activeforeground, -anchor, -background, -bg, -bitmap, -borderwidth, -bd, -cursor, -disabledforeground, -font, -foreground, -fg, -height, -highlightbackground, -highlightcolor, -highlightthickness, -image, -justify, -padx, -pady, -relief, -state, -takefocus, -underline, -width, and -wraplength.

Other options are:

-command => callback

Pointer to a function that will be called when the button is pressed.

-text => 'text'

Defines the text string displayed on the button. See also -textvariable.

-textvariable => \$variable

Points to the variable containing text to be displayed in the button. Button text will change as $variable does.

18.4.1 Button Methods

In addition to configure and cget, the following methods can be used for Button:


Causes the button to flash from the normal to active state colors.


Invokes the callback command as if the button were clicked.

Previous: 18.3 Common Widget Configuration OptionsPerl in a NutshellNext: 18.5 The Checkbutton Widget
18.3 Common Widget Configuration OptionsBook Index18.5 The Checkbutton Widget