Table of Options for Button-Type Widgets

The Button widgets share almost all of the same options. Table 4-1 shows a complete list of options and which widget they apply to. We’ll cover these options in more detail as we explore what Buttons can do.

In the details following Table 4-1, all information applies equally to Buttons, Checkbuttons, and Radiobuttons unless explictly stated otherwise.

Table 4-1. Options for Button-type widgets

Option

Button

Checkbutton

Radiobutton

-activebackground => color

Sets the color the background should be when the mouse cursor is over the Button. A color is a text string such as "red".

image with no caption

image with no caption

image with no caption

-activeforeground => color

Sets the color the text should be when the mouse cursor is over the Button.

image with no caption

image with no caption

image with no caption

-anchor => 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'center'

Causes the text to stick to the specified position in the Button.

image with no caption

image with no caption

image with no caption

-background => color

Sets the background of the Button to color.

image with no caption

image with no caption

image with no caption

-bitmap => 'bitmapname'

Sets default bitmap or the location of a bitmap file (with @ in front of path). See Chapter 17 for more details.

image with no caption

image with no caption

image with no caption

-borderwidth => amount

Changes the width of the edge drawn around the Button and the thickness of the indicator. Emphasizes the -relief of the Button.

image with no caption

image with no caption

image with no caption

-command => callback

Indicates a pointer to a function that will be called when the Button is pressed.

image with no caption

image with no caption

image with no caption

-cursor => 'cursorname'

Indicates that the mouse cursor will change to 'cursorname' when over the Button. See Chapter 23 for details.

image with no caption

image with no caption

image with no caption

-disabledforeground => color

Sets the color the text should be when the Button is disabled (-state will be 'disabled').

image with no caption

image with no caption

image with no caption

-font => 'fontname'

Changes the font of all text on the Button.

image with no caption

image with no caption

image with no caption

-foreground => color

Changes the text color to color.

image with no caption

image with no caption

image with no caption

-height => amount

Sets the height of the Button in characters if text is displayed and the screen distance if an image or bitmap is displayed.

image with no caption

image with no caption

image with no caption

-highlightbackground => color

Sets the color of the area behind the focus rectangle (shows when widget does not have focus).

image with no caption

image with no caption

image with no caption

-highlightcolor => color

Sets the color of the focus rectangle (shows when widget has focus).

image with no caption

image with no caption

image with no caption

-highlightthickness => amount

Sets the thickness of the highlight rectangle around the Button; indicates focus.

image with no caption

image with no caption

image with no caption

-image => $imgptr

$imgptr is a pointer to an Image object made with any supported image format. See Chapter 17 for details.

image with no caption

image with no caption

image with no caption

1

Determines whether to display the indicator.

image with no caption

image with no caption

'center'

Sets the direction against which multiline text will justify.

image with no caption

image with no caption

image with no caption

-offvalue => newvalue

Sets the value used when the Button is off. Must be a scalar. Default is 0.

image with no caption

-onvalue => newvalue

Sets the value used when the Button is on. Must be a scalar. Default is 1.

image with no caption

-padx => amount

Adds extra space to the left and right side of the Button inside the Button edge.

image with no caption

image with no caption

image with no caption

-pady => amount

Adds extra space to the top and bottom of the Button inside the Button edge.

image with no caption

image with no caption

image with no caption

-relief =>'flat'|'groove'|'raised'|'ridge'|'sunken'|'solid'

Changes the type of edges drawn around the Button. Default for Checkbutton and Radiobutton is 'flat'.

image with no caption

image with no caption

image with no caption

-selectcolor => color

Sets the color of the indicator when on.

image with no caption

image with no caption

-selectimage => imgptr

Indicates the image to display instead of text when Button is on. Ignored if -image is not used.

image with no caption

image with no caption

-state => 'normal' | 'disabled' | 'active'

Indicates the Button’s state of responsiveness. If set to 'disabled', the Button does not respond.

image with no caption

image with no caption

image with no caption

-takefocus => 0 | 1 | undef

Indicates that the Button will never get focus (0), always get focus (1), or let the application decide (undef).

image with no caption

image with no caption

image with no caption

-text => 'text'

Sets the text string displayed on the Button.

image with no caption

image with no caption

image with no caption

-textvariable => \$variable

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

image with no caption

image with no caption

image with no caption

-underline => n

Underlines the nth character in the text string. Allows keyboard input via that character when Button has the focus. It’s important to note that the character is only underlined; any behavior must be supplied by the programmer via a bind command. See Chapter 15 for binding details.

image with no caption

image with no caption

image with no caption

-value => newvalue

Sets the value assigned to $variable (with -variable option) when this Radiobutton is selected. Default is 1.

image with no caption

-variable => \$value

Associates the on/off values with $variable.

image with no caption

image with no caption

-width => amount

Sets the width of the Button in characters if text is displayed and as a screen distance if an image or bitmap is displayed.

image with no caption

image with no caption

image with no caption

-wraplength => amount

Sets the screen distance for the maximum amount of text displayed on one line. The default is 0, which means that text is not wrapped at word boundaries, only at line breaks (newlines).

image with no caption

image with no caption

image with no caption

Get Mastering 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.