Call button automatically

For some reason, this button automatically calls bot_analysis_framewithout pressing a button. I guess this is because it commandis a function with arguments.

Is there a way for a button to call only this function and pass the required variables only when pressed?

Button(topAnalysisFrame, text='OK', command=bot_analysis_frame(eventConditionL, eventBreakL)).pack(side=LEFT)
+3
source share
2 answers

Read the section here on transferring callbacks .

You store the result of this function in the command argument, not the function itself.

I believe that:

command = lambda: bot_analysis_frame(eventConditionL,eventBreakL)

may work for you.

+13
source

I am pretty sure that this was answered. Instead of this:

Button(topAnalysisFrame,
       text='OK',
       command=bot_analysis_frame(eventConditionL,eventBreakL)).pack(side=LEFT)

You can use lambda like this:

Button(topAnalysisFrame,
       text="OK",
       command=lambda: bot_analysis_frame(eventConditionL, eventBreakL)).pack(side=LEFT)
+1
source

Source: https://habr.com/ru/post/1778817/


All Articles