Repost: Tkinter Checkbox Question
Matthew Dixon Cowles
matt at mondoinfo.com
Sat Nov 23 22:03:21 EST 2002
Dear Josiah,
> What am I doing wrong in this sample? When I press the "status"
> button, the printout shows that "self.var.get()" returns a "0" weather
> the box is checked or not!
I'm sorry but I can't replicate that here. It doesn't look like
there's anything wrong with your code and if I paste it into an editor
window and run it, it behaves as I'd expect: the status button prints
0 if the checkbox isn't checked and 1 if it is. I doubt that it's a
problem that's related to the version of Python you're using
checkboxes are used all the time and many people would have run into
it.
Regards,
Matt
> #######################################################################
> from Tkinter import *
> root = Tk()
>
> class App:
>
> def __init__(self, master):
>
> frame = Frame(master)
> frame.grid()
>
> self.var = IntVar()
> self.CButton = Checkbutton(frame,text="check",variable=self.var)
> self.CButton.grid()
>
> self.buttonGo = Button(frame, text= "status", command=self.go)
> self.buttonGo.grid()
>
> def go(self):
> print self.var.get()
>
> app = App(root)
> root.mainloop()
> #######################################################################
More information about the Python-list
mailing list