Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Python » Tutorial » Radiobutton

Radiobutton in Python Tkinter

Create two radiobutton and choose anyone of them. Print the selected radiobutton on button click.

import tkinter as tk
from tkinter import StringVar

root = tk.Tk()

root.title('Example on radio button in Tkinter')

v = tk.IntVar()

def quit_loop():
    print("Value is: ", v.get())

tk.Label(root, text="""Choose a programming language:""", justify = tk.LEFT, padx = 20).pack()
tk.Radiobutton(root, text="Python", padx = 20, variable=v, value=0).pack(anchor=tk.W)
tk.Radiobutton(root, text="Perl", padx = 20, variable=v, value=1).pack(anchor=tk.W)
tk.Button(root, text = "OK", command=quit_loop).pack(anchor=tk.W) 

radiobutton = v.get()

Radiobutton in python tkinter