Next / Previous / Contents / TCC Help System / NM Tech homepage

14. The Radiobutton widget

Radiobuttons are sets of related widgets that allow the user to select only one of a set of choices. Each radiobutton consists of two parts, the indicator and the label:

To create a new radiobutton widget as the child of a root window or frame named master:

    w = Radiobutton ( master, option, ...  )

This constructor returns the new radiobutton widget. Options:

activebackgroundThe background color when the mouse is over the radiobutton. See Section 4.3, “Colors”.
activeforegroundThe foreground color when the mouse is over the radiobutton.
anchorIf the widget inhabits a space larger than it needs, this option specifies where the radiobutton will sit in that space. The default is anchor=CENTER. For other positioning options, see Section 4.5, “Anchors”. For example, if you set anchor=NE, the radiobutton will be placed in the top right corner of the available space.
bg or backgroundThe normal background color behind the indicator and label.
bitmapTo display a monochrome image on a radiobutton, set this option to a bitmap; see Section 4.7, “Bitmaps”.
borderwidthThe size of the border around the indicator part itself. Default is 2 pixels. For possible values, see Section 4.1, “Dimensions”.
commandA procedure to be called every time the user changes the state of this radiobutton.
cursorIf you set this option to a cursor name (see Section 4.8, “Cursors”), the mouse cursor will change to that pattern when it is over the radiobutton.
disabledforegroundThe foreground color used to render the text of a disabled radiobutton. The default is a stippled version of the default foreground color.
fontThe font used for the text. See Section 4.4, “Type fonts”.
fg or foregroundThe color used to render the text.
heightThe number of lines (not pixels) of text on the radiobutton. Default is 1.
highlightbackgroundThe color of the focus highlight when the radiobutton does not have focus. See Section 23, “Focus: routing keyboard input”.
highlightcolorThe color of the focus highlight when the radiobutton has the focus.
highlightthicknessThe thickness of the focus highlight. Default is 1. Set highlightthickness=0 to suppress display of the focus highlight.
imageTo display a graphic image instead of text for this radiobutton, set this option to an image object. See Section 4.9, “Images”. The image appears when the radiobutton is not selected; compare selectimage, below.
indicatoronNormally a radiobutton displays its indicator. If you set this option to zero, the indicator disappears, and the entire widget becomes a “push-push” button that looks raised when it is cleared and sunken when it is set. You may want to increase the borderwidth value to make it easier to see the state of such a control.
justifyIf the text contains multiple lines, this option controls how the text is justified: CENTER (the default), LEFT, or RIGHT.
padxHow much space to leave to the left and right of the radiobutton and text. Default is 1.
padyHow much space to leave above and below the radiobutton and text. Default is 1.
reliefBy default, a radiobutton will have FLAT relief, so it doesn't stand out from its background. See Section 4.6, “Relief styles” for more 3-d effect options. You can also use relief=SOLID, which displays a solid black frame around the radiobutton.
selectcolorThe color of the radiobutton when it is set. Default is red.
selectimageIf you are using the image option to display a graphic instead of text when the radiobutton is cleared, you can set the selectimage option to a different image that will be displayed when the radiobutton is set. See Section 4.9, “Images”.
stateThe default is state=NORMAL, but you can set state=DISABLED to gray out the control and make it unresponsive. If the cursor is currently over the radiobutton, the state is ACTIVE.
takefocusBy default, the input focus (see Section 23, “Focus: routing keyboard input”) will pass through a radiobutton. If you set takefocus=0, focus will not visit this radiobutton.
textThe label displayed next to the radiobutton. Use newlines ("\n") to display multiple lines of text.
textvariableIf you need to change the label on a radiobutton during execution, create a StringVar (see Section 22, “Control variables: the values behind the widgets”) to manage the current value, and set this option to that control variable. Whenever the control variable's value changes, the radiobutton's annotation will automatically change to that text as well.
underlineWith the default value of -1, none of the characters of the text label are underlined. Set this option to the index of a character in the text (counting from zero) to underline that character.
valueWhen a radiobutton is turned on by the user, its control variable is set to its current value option. If the control variable is an IntVar, give each radiobutton in the group a different integer value option. If the control variable is a StringVar, give each radiobutton a different string value option.
variableThe control variable that this radiobutton shares with the other radiobuttons in the group; see Section 22, “Control variables: the values behind the widgets”. This can be either an IntVar or a StringVar.
widthThe default width of a radiobutton is determined by the size of the displayed image or text. You can set this option to a number of characters (not pixels) and the radiobutton will always have room for that many characters.
wraplengthNormally, lines are not wrapped. You can set this option to a number of characters and all lines will be broken into pieces no longer than that number.

Methods on radiobutton objects include:

.deselect()

Clears (turns off) the radiobutton.

.flash()

Flashes the radiobutton a few times between its active and normal colors, but leaves it the way it started.

.invoke()

You can call this method to get the same actions that would occur if the user clicked on the radiobutton to change its state.

.select()

Sets (turns on) the radiobutton.