TypeError: <lambda>() takes no arguments (1 given)
Solution 1
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')
Solution 2
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')
Solution 3
You should consult Tkinter documentation:
Scale widget
command
- A procedure to be called every time the slider is moved. This procedure will be passed one argument, the new scale value. If the slider is moved rapidly, you may not get a callback for every possible position, but you'll certainly get a callback when it settles.
Button widget
command
- Function or method to be called when the button is clicked.
Change your lambda
to
command=lambda new_scale_val: scale_changed('LED')
evolutionizer
Updated on April 26, 2020Comments
-
evolutionizer over 3 years
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'))
-
monoid over 10 years
_
is traditionally used as marker of 'unused argument':command=lambda _: scale_changed('LED')