DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Create Radio Buttons in Python with Tkinter

A working Tkinter example showing mutually exclusive radio buttons, a default selection, how to read the selected value, and how to react with a callback.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a Tkinter radio-button group by giving each button a unique value and connecting all the buttons to the same StringVar or IntVar. Set that variable to choose a default, read the current choice with get(), and use a command callback when the interface should react to a selection.

Build a radio-button group with ttk

This runnable example creates three mutually exclusive choices, selects Python initially, and updates a label whenever the user changes the selection:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title("Choose a language")

selection = tk.StringVar(value="Python")
options = ("Python", "Rust", "Go")


def show_selection():
    result.config(text=f"Selected: {selection.get()}")


for option in options:
    ttk.Radiobutton(
        root,
        text=option,
        value=option,
        variable=selection,
        command=show_selection,
    ).pack(anchor="w")

result = ttk.Label(root, text=f"Selected: {selection.get()}")
result.pack(anchor="w", pady=8)

root.mainloop()

Save it as a Python file and run it in an environment with Tk support. The window opens with Python selected; choosing Rust or Go changes the label. The official Python Tkinter documentation describes a Radiobutton as a widget that presents an indicator and selects one choice from several.

How the shared variable and values work

selection is the control variable shared by every button in this group. Each button’s value is what gets written to that variable when selected. Because those values are distinct, selecting one choice replaces the previous value, rather than adding another selected item.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • text is the label shown to the user.
  • value is the value stored for that option; it can match the label, but does not have to.
  • variable connects the button to the shared StringVar.
  • command names a function to call after a user changes the selection.

Set the variable to one of the buttons’ values to establish a default selection, as tk.StringVar(value="Python") does above. If an answer is required but no default should be selected, initialize and validate the variable deliberately instead of assuming the user has chosen an option.

Read the selected value

Call selection.get() wherever you need the current choice. In the example, the callback reads it after a click and updates the label. You can also call get() later—for example, in a submit handler—to use the chosen value when the user submits a form.

Use a callback correctly

Pass the function itself as the command, as in command=show_selection. Do not write command=show_selection(): the parentheses run the function immediately while constructing the widget, rather than when the user selects an option.

Keep groups independent

Buttons connected to the same variable form one choice group. For a second, independent question, create a second control variable and connect that question’s buttons to it. The classic Radiobutton reference and ttk Radiobutton reference both document the shared-variable pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep a Python reference to each StringVar or IntVar for as long as its widgets use it. Python’s Tkinter variable documentation warns that garbage collection of a variable removes its underlying Tcl variable and can break the widget link.

Choose between Radiobutton and ttk.Radiobutton

tk.Radiobutton is the classic widget; ttk.Radiobutton is its themed counterpart. Both use a shared control variable and distinct values for mutually exclusive choices. Choose the one that fits the visual style of the rest of your interface. The example uses ttk.Radiobutton; with classic widgets, use tk.Radiobutton(parent, text=label, variable=selection, value=option).

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When radio buttons are the wrong control

Radio buttons suit a small set where exactly one option should be selected. Use checkbuttons when users may select multiple independent options. For a long list of choices, a list or dropdown can take less screen space.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.