How to collect values from Radiobutton Widget.


this is simple project to create Radiobuttons and collect their values. you can play with more GUI options to represent this in the way you like, below code is just to collect the values and to display them on IDLE console.


variable = IntVar()
this will help to collect the values of  Radiobutton,
A single IntVar() object is used to collect value as radio button is used to select one/many values. 


below is the code to collect values of Radio button, GUI will look like as above image


#program

try:
from Tkinter import *
except:
from tkinter import *

def collect():
a = v1.get()
print(a)


mw = Tk()

v1 = IntVar()

mw.geometry(
"600x100+50+50")
mw.title(
"AETies : Automation Expert Technologies")
mw.config(
background='#eeeeee')

l1 = Label(mw
, text=' Select Gender : ', bg='#eeeeee')
l1.pack(
side=LEFT)

rb1 = Radiobutton(mw
, text='Male\t', bg='#eeeeee', var=v1, value=1 )
rb1.pack(
side=LEFT)
rb2 = Radiobutton(mw
, text='Female\t', bg='#eeeeee', var=v1, value=2 )
rb2.pack(
side=LEFT)
bt = Button(mw
, text=' update ', command=collect).pack(side=LEFT)

mainloop()

 #Output

1 if male is selected
2 if female is selected




Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India