Python Tkinter Radiobutton
In Python GUI development, the Tkinter Radiobutton widget is used when an application needs to let the user choose one option from a group of choices. Unlike a checkbox, where multiple items can be selected, Radiobuttons are generally connected to the same control variable so that selecting one option automatically represents the current choice.
Each Radiobutton can be assigned a unique value, while a shared variable keeps track of which option the user has selected. Radiobuttons can contain text, multiple lines of text, or images, which makes them useful for creating interactive and user-friendly Tkinter applications.
You can also connect a function to a Radiobutton using the command option. This allows the application to perform a specific action whenever the user selects an option.
Table of Contents

Complete Advance AI Topics: Click Here
SQL Tutorial: Click Here
Syntax
The basic syntax for creating a Radiobutton widget in Tkinter is:
w = Radiobutton(top, options)
Here, top represents the parent or main window in which the Radiobutton will be placed. The options are configuration properties used to control its appearance and behavior.
Tkinter Radiobutton Options
Tkinter provides several options for customizing a Radiobutton. These options can control its color, size, text, state, alignment, selection behavior, and other properties.
| SN | Option | Description |
|---|---|---|
| 1 | activebackground | Sets the background color when the widget is active or focused. |
| 2 | activeforeground | Sets the text color when the widget is active. |
| 3 | anchor | Controls text positioning inside the widget. The default value is CENTER. |
| 4 | bg | Defines the background color of the Radiobutton. |
| 5 | bitmap | Displays a bitmap image instead of regular text. |
| 6 | borderwidth | Specifies the width of the widget border. |
| 7 | command | Executes a function when the Radiobutton selection changes. |
| 8 | cursor | Changes the mouse pointer when it is positioned over the widget. |
| 9 | font | Specifies the font style and size used by the widget. |
| 10 | fg | Sets the foreground or text color. |
| 11 | height | Defines the widget height in terms of text lines. |
| 12 | highlightcolor | Specifies the highlight color when the widget receives focus. |
| 13 | highlightbackground | Defines the highlight color when the widget does not have focus. |
| 14 | image | Displays an image instead of text. |
| 15 | justify | Controls the alignment of multiple lines of text using LEFT, CENTER, or RIGHT. |
| 16 | padx | Adds horizontal space inside the widget. |
| 17 | pady | Adds vertical space inside the widget. |
| 18 | relief | Controls the border appearance, such as FLAT, RAISED, or SUNKEN. |
| 19 | selectcolor | Defines the color shown when the Radiobutton is selected. |
| 20 | selectimage | Displays an alternate image when the Radiobutton is selected. |
| 21 | state | Controls the widget state, such as NORMAL or DISABLED. |
| 22 | text | Specifies the text displayed beside the Radiobutton. |
| 23 | textvariable | Uses a string variable to update the displayed text dynamically. |
| 24 | underline | Specifies the character position that should be underlined. |
| 25 | value | Assigns a unique value to the Radiobutton. |
| 26 | variable | Specifies the control variable used to track the selected option. |
| 27 | width | Sets the horizontal size of the widget in characters. |
| 28 | wraplength | Wraps long text into multiple lines after the specified length. |
Tkinter Radiobutton Methods
The Radiobutton widget also provides methods that can be used to control its selection state and trigger its associated command.
| SN | Method | Description |
|---|---|---|
| 1 | deselect() | Removes the selection from the Radiobutton. |
| 2 | flash() | Flashes the Radiobutton between its active and normal states. |
| 3 | invoke() | Executes the function associated with the command option. |
| 4 | select() | Selects the Radiobutton. |
Example: Implementing Radiobutton in Tkinter
The following example creates three Radiobuttons for selecting a favorite programming language. An IntVar is shared by all three buttons, and each button receives a different value. When the user makes a selection, the selection() function displays the selected value.
from tkinter import *
def selection():
selected_option = "You selected the option " + str(radio.get())
label.config(text=selected_option)
top = Tk()
top.geometry("300x150")
radio = IntVar()
lbl = Label(text="Favourite programming language:")
lbl.pack()
R1 = Radiobutton(
top,
text="Python",
variable=radio,
value=1,
command=selection
)
R1.pack(anchor=W)
R2 = Radiobutton(
top,
text="Java",
variable=radio,
value=2,
command=selection
)
R2.pack(anchor=W)
R3 = Radiobutton(
top,
text="C++",
variable=radio,
value=3,
command=selection
)
R3.pack(anchor=W)
label = Label(top)
label.pack()
top.mainloop()
Output
After running the program, a Tkinter window appears containing three choices: Python, Java, and C++. Because all three Radiobuttons use the same radio variable, the user can select only one option at a time.
When an option is selected, the command calls the selection() function. The selected value is retrieved using radio.get() and displayed in the label below the Radiobuttons.
YT:- DecodeIT
Frequently Asked Questions (FAQs)
1. What is a Radiobutton in Tkinter?
A Tkinter Radiobutton is a GUI widget that allows the user to select one option from a group of multiple choices.
2. How do you create a Radiobutton in Python Tkinter?
You can create a Radiobutton using the following syntax:
Radiobutton(parent, options)
3. How does Tkinter Radiobutton allow only one selection?
Multiple Radiobuttons are connected to the same control variable, such as IntVar() or StringVar(). Each button has a different value, so selecting one option updates the shared variable.
4. How can I get the selected Radiobutton value?
Use the get() method of the associated variable:
radio.get()
5. What is the use of the variable option in Radiobutton?
The variable option stores and tracks the current selection of the Radiobutton group.
6. What is the purpose of the value option?
The value option assigns a unique value to each Radiobutton. When a button is selected, its value is stored in the associated control variable.
7. How can I execute a function when a Radiobutton is selected?
Use the command option:
Radiobutton(root, text="Python", command=selection)
8. Can Tkinter Radiobutton display images?
Yes. The image option can be used to display an image instead of regular text. The selectimage option can display a different image when the Radiobutton is selected.
9. What are the main Radiobutton methods in Tkinter?
The main methods are select(), deselect(), flash(), and invoke().
10. What is the difference between a Tkinter Radiobutton and Checkbutton?
Radiobuttons are generally used when the user should select one option from a group, while Checkbuttons are used when multiple independent choices can be selected.
Conclusion
The Python Tkinter Radiobutton is an important widget for applications where users need to select one item from a predefined group of choices. By using the variable and value options together, developers can easily manage the selected option.
Tkinter Radiobuttons also provide numerous configuration options and useful methods for controlling their appearance and behavior. By combining Radiobuttons with functions, variables, labels, and other Tkinter widgets, you can build more interactive and intuitive Python GUI applications.
Keywords: Python Tkinter Radiobutton, tkinter radiobutton command, radio button tkinter get value, tkinter radiobutton default select, tkinter radiobutton documentation, radio button Python example, Python tkinter checkbox, tkinter radiobutton group, Python tkinter checkbutton, Python tkinter button, python tkinter radiobutton example, python tkinter radiobutton command, python tkinter radiobutton get value, python tkinter radiobutton set value, python tkinter radiobutton select, python tkinter radiobutton grid, python tkinter radiobutton default value