help with an error in Tkinter

Matt Gushee mgushee at havenrock.com
Wed Dec 15 22:24:32 EST 1999


Wayne <infotechsys at pivot.net> writes:

> class App:
>      def __init__(self, master):
>           self.var = IntVar()
>           c = Checkbutton(master, text = "Enable Tab", variable =
> self.var, command = self.cb
>           c.pack()
> 
>           self.button = Button(master, text = "Quit", fg = "red",
> commnad = master.quit
>           self.button.pack()
> 
>      def cb(self, event):
>           print "variable is", self.var.get()

This one's pretty simple: your definition of cb() calls for an 'event' 
argument, but widget commands (i.e., those that you specify in a
widget's 'command' attribute) don't take a second argument. You're
probably confusing this with an event binding, e.g.

	c.bind('<Button-1>', self.cb)

... in this case you would to define an event handler with an 'event'
argument, whether you actually used that argument or not. But in your
case, you can just write:

	def cb(self):

Voila!

BTW, if you want to write a function that can be called by either a
widget command or an event binding, you can do:

	def cb(self, event=None):

Hope this helps.

-- 
Matt Gushee
Portland, Maine, USA
mgushee at havenrock.com
http://www.havenrock.com/



More information about the Python-list mailing list