Next / Previous / Contents / Shipman's homepage

40. ttk.Radiobutton

This widget is the ttk version of Section 20, “The Radiobutton widget”. To create a ttk.Radiobutton widget as the child of a given parent widget, where the option values are given in Table 55, “ttk.Radiobutton options”:

    w = ttk.Radiobutton(parent, option=value, ...)

Table 55. ttk.Radiobutton options

class_ The widget class name. This may be specified when the widget is created, but cannot be changed later. For an explanation of widget classes, see Section 27, “Standardizing appearance”.
command A function to be called whenever the state of this radiobutton changes.
compound This option specifies the relative position of the image relative to the text when you specify both. The value may be tk.TOP (image above text), tk.BOTTOM (image below text), tk.LEFT (image to the left of the text), or tk.RIGHT (image to the right of the text). If you provide both image and text options but do not specify a value for compound, only the image will appear.
cursor The cursor that will appear when the mouse is over the radiobutton; see Section 5.8, “Cursors”.
image An image to appear on the radiobutton; see Section 5.9, “Images”.
style The style to be used in rendering this radiobutton; see Section 49, “Using and customizing ttk styles”.
takefocus By default, a ttk.Radiobutton will be included in focus traversal; see Section 53, “Focus: routing keyboard input”. To remove the widget from focus traversal, use takefocus=False.
text The text to appear next to the radiobutton, as a string.
textvariable A variable that controls the text that appears on the radiobutton; see Section 52, “Control variables: the values behind the widgets”.
underline If this option has a nonnegative value n, an underline will appear under the text character at position n.
value The value associated with this radiobutton. When the radiobutton is the one selected in the group, the value of this option will be stored in the control variable for the group.
variable A control variable that is shared by the other radiobuttons in the group; see Section 52, “Control variables: the values behind the widgets”. The type of this variable will be the same as the type you specify for the value options for the radiobuttons in the group.
width

Use this option to specify a fixed width or a minimum width. The value is specified in characters; a positive value sets a fixed width of that many average characters, while a negative width sets a minimum width.

You may also specify a width value in an associated style. If values are specified both in the widget constructor call and in the style, the former takes priority.


These options of the Tkinter Radiobutton widget are not supported by the ttk.Radiobutton constructor:

Table 56. ttk Radiobutton options not in ttk.Radiobutton

activebackground Use a style map to control the background option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
activeforeground Use a style map to control the foreground option.
anchor

Configure this option using a style; see Section 49, “Using and customizing ttk styles”. Use this option to specify the position of the text when the width option allocates extra horizontal space.

For example, if you specify options width=30 and compound=tk.BOTTOM on a radiobutton that displays both text and and image, and a style that specifies anchor=tk.W (west), the image will be at the left-hand end of the thirty-character space, with the text just above it.

When a radiobutton displays an image but no text, this option is ignored.

background or bg Configure the background option using a style. The bg abbreviation is not supported.
bitmap Not supported.
borderwidth or bd Configure this option using a style.
disabledforeground Use a style map for the foreground option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
font Configure this option using a style.
foreground or fg Configure the foreground option using a style. The fg abbreviation is not supported.
height Not supported.
highlightbackground To control the color of the focus highlight when the menubutton does not have focus, use a style map to control the highlightcolor option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
highlightcolor You may specify the default focus highlight color by setting this option in a style. You may also control the focus highlight color using a style map.
highlightthickness Configure this option using a style.
indicatoron Not supported.
justify Controls how multiple lines are positioned horizontally relative to each other. Configure this option using a style; values may be tk.LEFT, tk.CENTER, or tk.RIGHT for left-aligned, centered, or right-aligned, respectively.
offrelief Not supported.
overrelief Not supported.
padx Not supported.
pady Not supported.
relief Configure this option using a style.
selectcolor Not supported.
selectimage Not supported.
state In ttk, there is no option with this name. The state mechanism has been generalized; see Section 50.2, “ttk style maps: dynamic appearance changes”.
wraplength If you use a style that has this option set to some dimension, the text will be sliced into pieces no longer than that dimension.

Methods on a ttk.Radiobutton include all those described in Section 46, “Methods common to all ttk widgets”, plus:

.invoke()

When you call this method on a ttk.Radiobutton, the result is the same as if the user clicked on it: the indicator is set and the associated variable is set to the radiobutton's value. If there is a command associated with this radiobutton, that function is called, and the .invoke() method returns whatever the function returned; otherwise it returns None.