[Tutor] newbie:Problem with arguments for methods
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 22 Jan 2001 13:24:14 -0000
> self.hi_there = Button(frame, bitmap = "info",
> relief="raised", command=self.say_hi(self.viewer))
> def say_hi(self, canv):
>
> canv.create_oval(10,20,50,60)
> Before the small changes the button would write "print this"
> add the argument to self.say_hi it doesn't wait for me to
> press the button.
By putting parentheses after the say_hi you asked Python to call
the function and put the result as the action of the command.
command=
must have a function *object*(usually the name!) as a value.
Try something like this:
command=lambda c=self.viewer: say_hi(c)
lambda creates a new function which passes an argument, c to say hi.
We set the default value to the current viewer.
HTH,
Alan G.