且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Tkinter 中的按钮命令

更新时间:2023-09-29 18:20:46

command 期望没有 () 和参数的函数名.

command expect function name without () and arguments.

错误:

command=player.do_action(action, **action.kwargs)

通过这种方式,您可以分配给 player.do_action() 返回的 command 值,但此函数返回 None

This way you assign to command value returned by player.do_action() but this functions returns None

你必须使用 lambda 函数

command=lambda:player.do_action(action, **action.kwargs)

但也许您还需要 lambda 中的参数,因为您在 for 循环中创建了它.

but maybe you will need also arguments in lambda because you create this in for loop.

command=lambda act=action, kws=action.kwargs : player.do_action(act, **kws)