Featured Article

Master Radio Buttons in Python: Step-by-Step Guide

Nicole Jul 13, 2026

Radio buttons are a fundamental part of user interface design, and when it comes to creating interactive GUIs in Python, there's an array of libraries like Tkinter, PyQt, and wxPython that provide easy-to-use components for implementing these. In this article, we'll guide you through using radio buttons in Python primarily with Tkinter, and discuss some key facets such as event handling and grouping. Let's dive in!

Managing Radio buttons in Tkinter GUI by setting and reading selected values with options to disable
Managing Radio buttons in Tkinter GUI by setting and reading selected values with options to disable

First off, why use Tkinter? It's the most popular GUI library for Python due to its simplicity and the fact it comes bundled with Python, making it accessible on all platforms. Let's start by creating a simple application with a radio button.

Learn from Scratch Signal and Image Processing with Python GUI
Learn from Scratch Signal and Image Processing with Python GUI

Creating Radio Buttons with Tkinter

In Tkinter, a radio button is a type of Tkinter button. To make it into a radio button, we need to use the .config() method to set its -variable and -value options. Here's a basic example:

Python audio to text converter! ⭐️
Python audio to text converter! ⭐️

Single Radio Button

Let's see how to create and pack a single radio button.

Python
Python

<python>
    import tkinter as tk

    root = tk.Tk()
    tk.Radiobutton(root, text='Option 1', variable=x, value='1').pack()
    root.mainloop()
    </python>

The pack() is used to fill the root window.

Grouping Radio Buttons

To create radio buttons that are mutually exclusive, we need to group them by sharing the same StringVar.

Programming in Java Netbeans - A Step by Step Tutorial for Beginners: Lesson 41
Programming in Java Netbeans - A Step by Step Tutorial for Beginners: Lesson 41

<python>
    import tkinter as tk

    x = tk.StringVar()
    tk.Radiobutton(root, text='Option 1', variable=x, value='1').pack()
    tk.Radiobutton(root, text='Option 2', variable=x, value='2').pack()
    tk.Radiobutton(root, text='Option 3', variable=x, value='3').pack()
    </python>

Now, selecting one option will deselect all the others.

Radio Button Event Handling

Normally, we don't need to handle radio button events because their status (selected or not) is tied to the -variable option. But let's see how to catch the command event if needed:

Emojis in python
Emojis in python

Capturing the command Event

The command event fires when a radio button is selected. To catch it, we pass a callback function to the -command option.

Draw a Heart in Python Using Turtle Graphics ❤️
Draw a Heart in Python Using Turtle Graphics ❤️
How to Stay Current in Python? (Complete Guide)
How to Stay Current in Python? (Complete Guide)
9 Secret Samsung Phone Features
9 Secret Samsung Phone Features
a poster with the words string method in python
a poster with the words string method in python
an image of a computer screen with cats on it and the words, python list method
an image of a computer screen with cats on it and the words, python list method
How to Use the String join() Method in Python
How to Use the String join() Method in Python
Patient Information System in Python with Source Code and Database
Patient Information System in Python with Source Code and Database
How to use the "for Loop" in Python
How to use the "for Loop" in Python

<python>
    import tkinter as tk

    def select():
        print(f'Selected option: {x.get()}')

    x = tk.StringVar()
    tk.Radiobutton(root, text='Option 1', variable=x, value='1', command=select).pack()
    tk.Radiobutton(root, text='Option 2', variable=x, value='2', command=select).pack()
    </python>

In this snippet, the select() function is called every time a radio button is selected. It prints the current value of the -variable (i.e., the selected option).

Radio buttons are very flexible andcoupled with event handling, they can greatly enhance the interactivity of your Python applications. Well, that's it for today! Hope this guide helped you master using radio buttons in Python with Tkinter. Happy coding!