Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: <lambda>() takes no arguments (1 given)

I am a newbie to python programming and am still trying to figure out the use of lambda. Was worrking on some gui program after much googling i figured that i need to use this for buttons to work as i need it to

THIS WORKS

mtrf = Button(root, text = "OFF",state=DISABLED,command = lambda:b_clicked("mtrf"))

but when i do the same for Scale it does not work

leds = Scale(root,from_=0,to=255, orient=HORIZONTAL,state=DISABLED,variable =num,command =lambda:scale_changed('LED'))
like image 528
evolutionizer Avatar asked Apr 25 '13 12:04

evolutionizer


People also ask

How to fix “class takes no arguments (1 given) ” – TypeError?

This is a post to explain How To Fix Python TypeError – “Class Takes No Arguments (1 Given)”. This error occurs due to incorrect use of self parameter. The errors happens because the func () is a method within a Class. As such the first argument is expected to be a “self” parameter.

How do I fix object takes no arguments in Python?

Python TypeError: object () takes no arguments Solution. The arguments a class object accepts are passed through a function called __init__ (). If you misspell this function in your class declaration, you’ll encounter a “TypeError: object () takes no arguments” error when you run your code.

What does “object () takes no arguments” mean?

The arguments a class object accepts are passed through a function called __init__ (). If you misspell this function in your class declaration, you’ll encounter a “TypeError: object () takes no arguments” error when you run your code. In this guide, we talk about what this error means and why you may encounter it.

Why does Python take 0 positional arguments but 1 was given?

The Python "TypeError: takes 0 positional arguments but 1 was given" occurs for multiple reasons: Forgetting to specify the self argument in a class method. Forgetting to specify an argument in a function. Passing an argument to a function that doesn't take any arguments.


2 Answers

Scale calls the function passed as command with one argument, so you have to use it (although throw it away immediately).

Change:

command=lambda: scale_changed('LED')

to

command=lambda x: scale_changed('LED')
like image 142
eumiro Avatar answered Sep 24 '22 18:09

eumiro


This is presumably because the command is passed an argument that perhaps you don't want. Try changing the lambda from

command=lambda:scale_changed('LED')

to

command=lambda x:scale_changed('LED')
like image 22
Alex Avatar answered Sep 23 '22 18:09

Alex