Skip to content

RadioGroup

A RadioGroup is a group of radio buttons, of which only one can be selected at a time. Use Radio Buttons when the user must select exactly one option from a small set of mutually exclusive choices that should all be visible at once.

Examples

Plan Select

This app shows how the on_change event can be used to update a label when the user selects a different radio button in the group.

plan_select.py
import gooeypie as gp
def display_minimum_spend(event):
"""Display the minimum spend for the selected plan."""
plan = plan_radios.selected
if plan == "Super saver":
result_label.text = "Minimum spend: $180"
elif plan == "Standard":
result_label.text = "Minimum spend: $250"
elif plan == "Premium":
result_label.text = "Minimum spend: $350"
app = gp.GooeyPieApp("Plan Selector")
app.width = 250
# Plan selection label and radio buttons
plans = ["Super saver", "Standard", "Premium"]
plan_label = gp.Label("Select your plan:")
plan_radios = gp.RadioGroup(plans)
# Update minimum spend label when the selection changes
plan_radios.on_change(display_minimum_spend)
# Frame for plan details
plan_frame = gp.Frame()
plan_frame.add(plan_label, 1, 1, align_horizontal="left")
plan_frame.add(plan_radios, 1, 2, align_horizontal="left")
# Result label, initially empty
result_label = gp.Label()
# Add widgets to window
app.add(plan_frame, 1, 1, expand_horizontal=True)
app.add(result_label, 1, 2)
app.run()

Creating a RadioGroup widget

my_radio_group = gp.RadioGroup(options, orientation)

Parameters

  • options (list of strings): The labels for the radio buttons in the group. The number of items in the list determines how many radio buttons are in the group.
  • orientation (string): Optional. The orientation of the radio buttons in the group. Either "horizontal" or "vertical". Default is "vertical".

Properties

Name Type Description
.selected string Gets or sets the label of the currently selected radio button in the group. Setting this property will change the selected radio button to the one with the specified label.
.selected_index integer Gets or sets the index (starting from 0) of the currently selected radio button in the group. Setting this property will change the selected radio button to the one at the specified index.
.orientation string Gets or sets the orientation of the radio buttons in the group. Either "horizontal" or "vertical". Default is "vertical". This property cannot be changed after the radio group is added to a layout.
.options list of strings Gets the labels for the radio buttons in the group. The options cannot be changed after the radio group is created.
.width integer Gets or sets the width of the radio group in pixels.
.height integer Gets or sets the height of the radio group in pixels.
.disabled boolean Gets or sets whether the radio group is disabled. When disabled is set to True, the radio buttons in the group do not respond to click events.

Methods

Name Returns Description
.disable_item(item_label) None Disables the radio button with the specified label. A disabled radio button does not respond to click events and is visually indicated as disabled.
.enable_item(item_label) None Enables the radio button with the specified label.
.disable_index(index) None Disables the radio button at the specified index. A disabled radio button does not respond to click events and is visually indicated as disabled.
.enable_index(index) None Enables the radio button at the specified index.

Events

This widget supports the following events as well as the standard events listed below.

Name Description
.on_change(event_function) The function to call when the selected radio button in the group changes. This event is triggered whenever the user clicks on a radio button in the group or when the selected radio button is changed programmatically.

Standard events

  • .on_click
  • .on_double_click
  • .on_right_click
  • .on_middle_click
  • .on_mouse_down
  • .on_mouse_up
  • .on_mouse_enter
  • .on_mouse_leave

Styles

Styles for this widget

How to specify colors

  • Colors can be specified as either a hex code (e.g. "#FF0000"), a CSS color name, or "transparent".
  • When specifying a color for a style, you can provide either a single color or two colors separated by a comma. If you provide two colors, the first will be used for light mode and the second for dark mode. For example, my_widget.text_color = "steelblue", "skyblue" would specify steelblue for light mode and sky blue for dark mode.
Name Description Default
.style.checked_border_color The color of the border of the selected radio button in the group.
.style.checked_border_width The width of the border of the selected radio button in the group. 5
.style.hover_color The color of the radio buttons in the group when hovered over.
.style.size The size of the radio buttons in the group.
.style.text_color The color of the text of the radio buttons in the group.
.style.text_disabled_color The color of the text of the radio buttons in the group when they are disabled.
.style.unchecked_border_color The color of the border of the unselected radio buttons in the group.
.style.unchecked_border_width The width of the border of the unselected radio buttons in the group. 3
.style.font_name The font of the text of the button. Either an installed font or a generic font name: "serif", "sans-serif", "monospace" or "system" "system"
.style.font_size The size of the text of the button. 12
.style.font_weight The weight of the text of the button. Either "normal" or "bold". "normal"
.style.font_style The style of the text of the button. Either "normal" or "italic". "normal"