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 + Textfield Saving to Variable

    Pythonista
    2
    5
    3365
    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.
    • techteej
      techteej last edited by

      I'm just starting to use the ui module. How would I connect a button to a textfield to save the text to a variable? This is what I have so far.

      # coding: utf-8
      
      import ui
      
      v = ui.load_view('Untitled 2')
      textfield = v['textfield1']
      button1 = v['button1']
      v.present('sheet')
      
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        You need to assign an action to your button. This is basically just a function that gets called automatically when your button is tapped. Example, based on your code:

        # coding: utf-8
        
        import ui
        
        v = ui.load_view('Untitled 2')
        textfield = v['textfield1']
        
        def button_action(sender):
            text = textfield.text
            print text
        
        button1 = v['button1']
        button1.action = button_action
        v.present('sheet')
        

        You can also set the action directly in the UI editor instead of assigning it in code (you would just enter "button_action" there, but you need to make sure that the function is defined before you load the view).

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

          Ok thank you. How do I dismiss this without user having the tap the x? Is that possible?

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

            Calling ui.close_all() is the easiest way.

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

              Thanks again!

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