出于某种原因,此按钮在没有按下按钮的情况下自动调用bot_analysis_frame
。我猜是因为command
是带参数的函数。
有没有办法让按钮只调用此函数并在按下时传递所需的变量 ?
Button(topAnalysisFrame, text='OK', command=bot_analysis_frame(eventConditionL, eventBreakL)).pack(side=LEFT)
答案 0 :(得分:13)
请阅读此处有关传递callbacks。
的部分您正在将该函数的结果存储到command参数而不是函数本身。
我相信:
command = lambda: bot_analysis_frame(eventConditionL,eventBreakL)
可能适合你。
答案 1 :(得分:1)
我很确定之前已经回答了这个问题。而不是:
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)