Python Tkinter RadioButtons Widget Get Selected Value and Display it Full Example For Beginners

Python Tkinter RadioButtons Widget Get Selected Value and Display it Full Example For Beginners

 

Welcome folks today in this blog post we will be looking on how to get the value of radiobutton which is selected inside tkinter in python. All the full source code of application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

#radioBut.py simple radio buttons
#andyp 12.09.12

import tkinter

def sel():
    selection = ' Dude you want  ' + str(var.get()) + ' Ice Cream'
    label.config(text=selection)

app = tkinter.Tk()
var=tkinter.IntVar()

r1= tkinter.Radiobutton(app, text = 'Chocolate',variable=var,value=1,command=sel)
r2=tkinter.Radiobutton(app, text = 'Strawberry',variable=var,value=2,command=sel)
r3= tkinter.Radiobutton(app, text = 'Vanilla',variable=var,value=3,command=sel)
r1.pack()
r2.pack()
r3.pack()

label=tkinter.Label(app)
label.pack()
app.mainloop()

 

See also  Python 3 BeautifulSoup4 Script to Extract All H1,H2 & H3 Tags in Given HTML5 Webpage Full Project For Beginners

 

Now if you execute the above python script by typing the below command as shown below

 

python app.py

 

Leave a Reply