passing arguments from scale widget to function
m7b52000
tpearce at internode.on.net
Mon Aug 22 13:57:06 CEST 2005
Matt Hammond wrote:
> On Mon, 22 Aug 2005 12:16:01 +0100, m7b52000 <tpearce at internode.on.net>
> wrote:
>
>>> command = lambda : Calc(a.get())
>
>
>> I get the following message when I use lambda as above:
>>
>> TypeError: <lambda>() takes no arguments (1 given)
>
>
> Oops, forgot! The Scale widget outputs a single argument - the value of
> the slider. You therefore could write:
>
> command = lambda value : Calc(value)
>
> or even simpler:
>
> command = Calc
>
> In the latter case, you're supplying your "calc" function as the
> function to be called. Calc takes a single argument - the value of the
> slider, so it fulfills the task. Note that we're passing "Calc" (the
> function itself), not "Calc(...)" (the result of calling the function)
>
> regards
>
>
> Matt
>
Ahhhh. Partial success with : command = Calc. A slider will now pass its
argument to a function without problem. My Calc function however is
expecting 3 arguments - 1 from each slider i.e moving any of the 3
sliders should cause a recalculation. I am now getting the following error:
TypeError: Calc() takes exactly 3 arguments (1 given)
p.s your help is much appreciated....
More information about the Python-list
mailing list