multiple check boxes

H

Harish Vaidya

hi,
i am trying to use multiple checkboxes.
what is happening is once select check box its
variable is not getting set. below is the code. what
could be the problem? i am using python 2.0
thanks in advance
=============
from Tkinter import *

def TestCases():

print 'hi'
if(name3.var.get() == 1):
print 'TEST CASE A'


def hostTC():
if(name1.var.get() == 1):
print 'TESTSCENARIO A'
top = Tk()
y1 = IntVar()
name3 = Checkbutton(top, text = "TEST CASE A",
variable = y1, onvalue=1, offvalue=0)
name3.grid()
y2 = IntVar()
name4 = Checkbutton(top, text="TEST CASE B",
variable = y2, onvalue=1, offvalue=0)
name4.grid()
name3.var = y1
name4.var = y2
b1 = Button(top,
text='OK!',command=TestCases())
name3.pack()
name4.pack()
b1.pack()
Tkinter.mainloop()



def main():
global root,name1,name2,name3
root = Tk()
x1 = IntVar()
name1 = Checkbutton(root, text = "Pizza", variable
= x1, onvalue=1, offvalue=0)
name1.grid()
x2 = IntVar()
name2 = Checkbutton(root, text="Salad", variable =
x2, onvalue=1, offvalue=0)
name2.grid()
name1.var = x1
name2.var = x2
b = Button(root, text='OK!',command=hostTC())
name1.pack()
name2.pack()
b.pack()
Tkinter.mainloop()


if __name__ == '__main__':

main()



__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
 
P

Peter Otten

Harish said:
hi,
i am trying to use multiple checkboxes.
what is happening is once select check box its
variable is not getting set. below is the code. what
could be the problem? i am using python 2.0
thanks in advance

I do not fully understand what you're are trying to achieve with your code,
but this observation might help you anyway:

[...]
b1 = Button(top,
text='OK!',command=TestCases()) [...]
b = Button(root, text='OK!',command=hostTC())
[...]

In both cases you do the eqivalent of

b = Button(..., command=None)

as both TestCases() and hostTC() do not explicitly return a value.
You probably want the buttons to invoke TestCases() or hostTC(), and you
therefore must omit the trailing (), e. g.:

b = Button(root, text='OK!',command=hostTC)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top