Python 类型错误:<lambda>() 不接受任何参数(给定 1 个)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16215045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: <lambda>() takes no arguments (1 given)
提问by evolutionizer
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
我是 python 编程的新手,并且仍在尝试弄清楚 lambda 的用法。经过大量谷歌搜索后,我正在研究一些 gui 程序,我想我需要使用它来使按钮工作,因为我需要它
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
但是当我对 Scale 做同样的事情时它不起作用
leds = Scale(root,from_=0,to=255, orient=HORIZONTAL,state=DISABLED,variable =num,command =lambda:scale_changed('LED'))
采纳答案by eumiro
Scalecalls the function passed as commandwith one argument, so you have to use it (although throw it away immediately).
Scale调用作为command一个参数传递的函数,因此您必须使用它(尽管立即将其丢弃)。
Change:
改变:
command=lambda: scale_changed('LED')
to
到
command=lambda x: scale_changed('LED')
回答by AlexFoxGill
This is presumably because the command is passed an argument that perhaps you don't want. Try changing the lambda from
这可能是因为该命令传递了一个您可能不想要的参数。尝试将 lambda 从
command=lambda:scale_changed('LED')
to
到
command=lambda x:scale_changed('LED')
回答by jamylak
You should consult Tkinter documentation:
您应该查阅 Tkinter文档:
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.
缩放小部件
command- 每次移动滑块时调用的过程。此过程将传递一个参数,即新的比例值。如果滑块快速移动,您可能不会在每个可能的位置都得到回调,但是当它稳定下来时,您肯定会得到回调。按钮小部件
command- 单击按钮时要调用的函数或方法。
Change your lambdato
改变你lambda的
command=lambda new_scale_val: scale_changed('LED')

