Forum Archive

Button.action runs as I add the button to the View

rui_mac

Ok, I'm very new to this. Although I already coded in python before, I only have Pythonista for a couple of days.
My problem is the following:

I'm creating a new layout using code, not the UI editor.
I created a new button and set its action to a method I created with:

my_button.action=get_action(pn)

the pn is an array that I must check somehow (but that is not important).
The problem is that as soon as I add the button to the view, the get_action method gets called.
Shouldn't it only be called when the button is pressed?
Please, help me out with this.

omz

get_action(pn) is a regular function call, to assign the action to the button, you need to use the function name without parentheses:

my_button.action = get_action
rui_mac

Thank you so much.
It is working now.
However, to check for something inside that array, I need to make it global, right?
Otherwise, how can I send it over to the action method when the button is pressed?