How to collect values from Checkbutton Widget.


this is simple project to create checkbuttons 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 check button
An indivisual IntVar() object is used to collect value as check button is used to select 2 or more/many values.


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

#program

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

def collect():
a = v1.get()
b = v2.get()
c = v3.get()
d = v4.get()
print('a b c d ')
print(a, b, c, d)


mw = Tk()

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

v1 = IntVar()
v2 = IntVar()
v3 = IntVar()
v4 = IntVar()

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

cb1 = Checkbutton(mw
, variable=v1, text='Python\t', bg='#eeeeee', onvalue=1, offvalue=0).pack(side=LEFT)
cb2 = Checkbutton(mw
, variable=v2, text='C++\t', bg='#eeeeee', onvalue=1, offvalue=0).pack(side=LEFT)
cb3 = Checkbutton(mw
, variable=v3, text='.Net\t', bg='#eeeeee', onvalue=1, offvalue=0).pack(side=LEFT)
cb4 = Checkbutton(mw
, variable=v4, text='Java\t', bg='#eeeeee', onvalue=1, offvalue=0).pack(side=LEFT)
bt = Button(mw
, text=' submit ', command=collect).pack(side=LEFT)

mainloop()
 #Output

a b c d
1 1 0 0






Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India