admin管理员组文章数量:1123943
I've seen this a lot online but with no discernable rhyme or reason. When creating an event binding, why call "lambda: thefunction() " instead of just passing " thefunction"? -- especially when nothing needs passed to said function?
ie. self.button = tk.Button(root, command= lambda:arb_func_call()
vs. self.button = tk.Button(root, command= arb_func_call
is this a matter of style or is there a reason to use x over y?
I've seen this a lot online but with no discernable rhyme or reason. When creating an event binding, why call "lambda: thefunction() " instead of just passing " thefunction"? -- especially when nothing needs passed to said function?
ie. self.button = tk.Button(root, command= lambda:arb_func_call()
vs. self.button = tk.Button(root, command= arb_func_call
is this a matter of style or is there a reason to use x over y?
Share Improve this question asked yesterday StarscreamStarscream 251 silver badge9 bronze badges 1 |1 Answer
Reset to default 0There is no reason to use lambda
for the command
attribute of a button, unless you need the command to pass one or more arguments. The lambda
with no arguments only serves to make the code more complicated than it needs to be.
本文标签: functionWhy use commandlambdasomefunction() vs commandsomefunction in button commandsStack Overflow
版权声明:本文标题:function - Why use command=lambda : somefunction() vs command=somefunction in button commands? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736609765a1945415.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
arb_func_call
, both approaches are equivalent. I prefer thecommand=arb_func_call
because it's shorter and more readable to me but I uselambda
if I am passing arguments to the callback function. – TheLizzard Commented yesterday