takes no arguments (1 given)

Tommy Grav tgrav at mac.com
Mon Dec 3 14:24:11 EST 2007


On Dec 3, 2007, at 2:10 PM, Mike wrote:

> In the following Display inherits from the Tkinter class Canvas:
>
> import sys
> from Tkinter import *
> class Display(Canvas) :
> ...
>     def fill_canvas() :
def fill_canvas(self):
>         slop=self.slop
>         set_sr(int(self.cget('width'))+slop,
>                   int(self.cget('height'))+slop)
>         self.refresh()
> ...
>
> disp=Display(fred, None)
> disp.pack()
> def stupid(unused) : disp.fill_canvas()
> disp.bind("<Configure>", stupid)
> mainloop()
>
>> From the above I get:
> Exception in Tkinter callback
> ...
>   File Ca_canvas.py, line 173, in stupid
>       def stupid(unused) : disp.fill_canvas()
> TypeError: fill_canvas() takes no arguments (1 given)
>
>
> What is going on?
> I tried to do something similar with lambda
> and got the same result.

The class method needs a self argument so that
disp.fill_canvas() can parse the class instance disp
to the method.

Cheers
   TG




More information about the Python-list mailing list