按钮命令被自动调用
出于某种原因,这个按钮在没有被按下的情况下,自动调用了 bot_analysis_frame
这个函数。我猜可能是因为 command
是一个带参数的函数。
有没有办法让这个按钮只在被按下的时候才调用这个函数,并且只传递需要的变量呢?
Button(topAnalysisFrame, text='OK', command=bot_analysis_frame(eventConditionL, eventBreakL)).pack(side=LEFT)
2 个回答
2
我很确定这个问题之前有人回答过。与其这样写:
Button(topAnalysisFrame,
text='OK',
command=bot_analysis_frame(eventConditionL,eventBreakL)).pack(side=LEFT)
你可以这样使用lambda:
Button(topAnalysisFrame,
text="OK",
command=lambda: bot_analysis_frame(eventConditionL, eventBreakL)).pack(side=LEFT)
14
请查看这里关于传递回调函数的部分。
你实际上是把那个函数的结果存储到了命令参数里,而不是存储函数本身。
我觉得这个:
command = lambda: bot_analysis_frame(eventConditionL,eventBreakL)
可能对你有帮助。