help with an error in Tkinter
Ivan Van Laningham
ivanlan at callware.com
Wed Dec 15 22:20:47 EST 1999
Hi All--
Wayne wrote:
>
> Hello,
> I'm reading the book(?) " An introduction to Tkinter" and in doing one
?? Who's the author?
> of the example
> on Checkbutton Widget I get an error that I don't know how to resolve.
> Here is the program
> with a slight change - I left the "Quit" button code in from an earlier
> example.
>
> from Tkinter import *
>
> 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()
>
> root = Tk()
> app = App(root)
> root.mainloop()
>
> The error I'm getting:
>
> Exception in Tkinter callback
> Traceback (innermost last):
> File "/var/tmp/python-root/usr/lib/python1.5/lib-tk/Tkinter.py", line
> 752, in __call__
> return apply(self.func, args)
> TypeError: not enough arguments; expected 2, got 1
>
Here's a corrected version:
from Tkinter import *
class App:
def __init__(self, master):
self.var = IntVar()
# You need to close the parens.
c = Checkbutton(master, text = "Enable Tab", variable
=self.var, command = self.cb)
c.pack()
# You need to close the parens, and spell it "command", not "commnad"
self.button = Button(master, text = "Quit", fg = "red",
command = master.quit)
self.button.pack()
# And here, the "command" callback doesn't get passed the
"event" parameter.
def cb(self, event=0):
print "variable is", self.var.get()
root = Tk()
app = App(root)
root.mainloop()
Proofread lots.
<or,-measure-three-times-cut-once>-ly y'rs,
Ivan;-)
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
ivanlan at home.com
http://www.pauahtun.org
See also:
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
----------------------------------------------
More information about the Python-list
mailing list