omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


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

    Editorial
    2
    3
    1903
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rui_mac
      rui_mac last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        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
        
        1 Reply Last reply Reply Quote 0
        • rui_mac
          rui_mac last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors