Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: 18.5 The Checkbutton WidgetChapter 18
Perl/Tk
Next: 18.7 The Label Widget
 

18.6 The Radiobutton Widget

Create a radiobutton with the Radiobutton method. A radiobutton has an indicator to the left of the label indicating whether the button is selected. It differs from a checkbutton in that only one button may be selected at the same time. Each button in a group of radiobuttons uses the same variable specified with the -variable option; when selected, the button assigns that variable the value specified by the -value option.

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

Other options are:

-command => callback

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

-indicatoron => boolean

Determines whether or not to display the indicator. Default is on (1).

-selectcolor => color

Color of the indicator when the radiobutton is on.

-selectimage => imgptr

Defines the image to be displayed instead of text when the radiobutton is on. Ignored if -image is not used.

-text => 'text'

Defines the text string displayed in the radiobutton. See also -textvariable.

-textvariable => \$variable

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

-value => value

Sets $variable to the specified value when the radiobutton is selected (default is 1).

-variable => \$variable

Associates the on/off value of the indicator with the specified variable.

18.6.1 Radiobutton Methods

In addition to configure and cget, the following methods are supported by Radiobutton:

deselect

Deselects the button and sets the variable to the empty string.

select

Sets the radio button.

flash

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

invoke

Selects the button and invokes the callback command as if the radiobutton were clicked.


Previous: 18.5 The Checkbutton WidgetPerl in a NutshellNext: 18.7 The Label Widget
18.5 The Checkbutton WidgetBook Index18.7 The Label Widget