Previous section   Next section

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 27.  Buttons and Menus

Button Attributes

Table 27-1 lists the attributes for the button, checkbutton, menubutton, and radiobutton widgets. Unless otherwise indicated, the attributes apply to all of these widget types. Chapters 37, 38, and 39 discuss many of these attributes in more detail. Some attributes are ignored on the Windows and Macintosh platforms because they are not supported by the native button widgets.

The table uses the resource name for the attributes, which has capitals at internal word boundaries. In Tcl commands, the attributes are specified with a dash and they are all lowercase. Compare:

option add *Menubutton.activeBackground: red
.mb configure -activebackground red

The first command defines a resource database entry that covers all menubuttons and gives them a red active background. This only affects menubuttons created after the database entry is added. The second command changes an existing menubutton (.mb) to have a red active background. Note the difference in capitalization of background in the two commands. The resource database is introduced on page 311, and Chapter 28 explains how to use the resource database in more detail.

Table 27-1. Resource names of attributes for all button widgets.
activeBackgroundBackground color when the mouse is over the button.
activeForegroundText color when the mouse is over the button.
anchorAnchor point for positioning the text.
backgroundThe normal background color.
bitmapA bitmap to display instead of text.
borderWidthWidth of the border around the button.
commandTcl command to invoke when button is clicked.
cursorCursor to display when mouse is over the widget.
defaultactive displays as a default button. normal and disabled display as normal button. See page 715 (Tk 8.0).
directionup, down, left, right, active. Offset direction for posting menus. menubutton. (Tk 8.0).
disabledForegroundForeground (text) color when button is disabled.
fontFont for the text.
foregroundForeground (text) color. (Also fg).
heightHeight, in lines for text, or screen units for images.
highlightBackgroundFocus highlight color when widget does not have focus.
highlightColorFocus highlight color when widget has focus.
highlightThicknessWidth of highlight border.
imageImage to display instead of text or bitmap.
indicatorOnBoolean that controls if the indicator is displayed: checkbutton, menubutton, or radiobutton.
justifyText justification: center, left, or right.
menuMenu posted when menubutton is clicked.
offValueValue for Tcl variable when checkbutton is not selected.
onValueValue for Tcl variable when checkbutton is selected.
padXExtra space to the left and right of the button text.
padYExtra space above and below the button text.
reliefflat, sunken, raised, groove, solid or ridge.
selectColorColor for selector. checkbutton or radiobutton.
selectImageAlternate graphic image for selector: checkbutton or radiobutton.
stateEnabled (normal) or deactivated (disabled).
takeFocusControl focus changes from keyboard traversal.
textText to display in the button.
textVariableTcl variable that has the value of the text.
underlineIndex of text character to underline.
valueValue for Tcl variable when radiobutton is selected.
variableTcl variable associated with the button: checkbutton or radiobutton.
widthWidth in characters for text, or screen units for image.
wrapLengthMaximum character length before text is wrapped, in screen units.

      Previous section   Next section