Radiobutton in Tkinter in Python by R4R Team

The radiobutton widget is used to display a number of options to a user as toggle buttons. The user can then select only one options by clicking the button corresponding to each option.

Syntax-

c=Radiobutton(window,option=value)


program-



from tkinter import *
#create a window screen
win=Tk()
win.geometry("400x350")

def show():
if var.get()==1:
data="You select Madhya pradesh"
if var.get()==2:
data="You select Bihar"
if var.get()==3:
data="You select Delhi"
l.config(text=data)


Label(win,text="Select City",bg="green",fg="White").place(x=80,y=70)
var=IntVar()
r1=Radiobutton(win,text="Madhya pradesh",variable=var,value=1,command=show)
r1.place(x=80,y=100)

r2=Radiobutton(win,text="Bihar",variable=var,value=2,command=show)
r2.place(x=80,y=120)

r3=Radiobutton(win,text="Delhi",variable=var,value=3,command=show)
r3.place(x=80,y=140)

l=Label(win,text="initially no one selected",bg="green",fg="White")
l.place(x=80,y=170)

#hold the screen
win.mainloop()


output-



-In this program, we create a Radiobutton for selecting a one city
-According to select button we show selected city in the Label.

Click different option and show different ans-





Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!