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

33,457

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')
Share:
33,457
evolutionizer
Author by

evolutionizer

Updated on April 26, 2020

Comments

  • evolutionizer
    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
    monoid over 10 years
    _ is traditionally used as marker of 'unused argument': command=lambda _: scale_changed('LED')