类型错误:<lambda>()

2024-04-28 14:43:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python编程的新手,仍在尝试使用lambda。在谷歌搜索了很多东西之后,我开始研究一些gui程序,我想我需要用它来让按钮按我需要的方式工作

这有效

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

但当我对Scale做同样的操作时,就不起作用了

leds = Scale(root,from_=0,to=255, orient=HORIZONTAL,state=DISABLED,variable =num,command =lambda:scale_changed('LED'))

Tags: lambdatext程序编程方式guibuttonroot
3条回答

你应该咨询Tkinterdocumentation

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.

lambda更改为

command=lambda new_scale_val: scale_changed('LED')

Scale使用一个参数调用作为command传递的函数,因此必须使用它(尽管立即将其丢弃)。

更改:

command=lambda: scale_changed('LED')

command=lambda x: scale_changed('LED')

这可能是因为命令传递了一个参数,而您可能不希望这样做。尝试将lambda从

command=lambda:scale_changed('LED')

command=lambda x:scale_changed('LED')

相关问题 更多 >