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.


    How to save user input from text field and use throughout script with ui?

    Pythonista
    5
    8
    9634
    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.
    • Taje
      Taje last edited by Taje

      How do I use the input placed in the ui text field for making decisions, comparisons, and evaluations to determine what the script and ui does next. Thank you.

      https://gist.github.com/6a2a5ec0f5de07b4d3aa988077c5bbd0

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Taje last edited by JonB

        @Taje
        Please go back and edit your post, placing triple backticks before the first line of code, and after the last.

        On iOS the backtick is found by pressing the .?123 button, long pressing the single quote, and choosing the backtick:

         ```
        

        For really long scripts, posting a gist will be better. You can use the share menu to post to gist, then simply paste the link back here. That makes it easier for people to copy your code and run it.

        Taje 1 Reply Last reply Reply Quote 0
        • Taje
          Taje @JonB last edited by

          @JonB thank you and my apologies but is a gist like get GitHub or is it something else? I'm not familiar with gist and my search on it came back as a vocabulary word not a reference to websites or computer terms.

          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @Taje last edited by

            @Taje, you can create a gist directly from your file in Pythonista, check the action ("wrench") menu. You get a link to your code.

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

              In any case, instead of posting the whole vode with all the labels etc., which are not likely to be relevant to your issue, please try to state your problem as a simple question, supported by just the key bits of code, e.g. around the TextField and TextView. As a bonus, often creating that shorter code will help you understand the problem better.

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

                You can use a class. eg:

                class Example:
                		def demo():
                			Example.a = input('text: ')
                		def check_input():
                			print(Example.a)
                

                To run these functions:

                x = Example()
                Example.demo()
                Example.check_input()
                

                You can make a UI implementation quite simply based off of that.

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

                  If you were looking for a ui.textfield, try this:

                  If you want to store the input in a variable, I would suggest this way.
                  Define a function to look for input in the text field

                  def getInput(view):
                      textfield = view["textfield name"]
                      input = textfield.text
                      return input
                  
                  #Now you can define a variable to keep track of the input.
                  #Use the function only when you want to update your variable.
                  
                  inp = ''
                  #Load your view or create it here
                  v = ui.View()
                  #create textfield
                  v.add_subview(textfield)
                  v.present()
                  #Maybe add a button that triggers the getInput() function
                  b = ui.Button()
                  b.action = getInput
                  v.add_subview(b)
                  
                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by JonB

                    You might want either an action method for a button or textfield, or a textfield delegate method. Then you could have sort of a graphical console.

                    Simple example:

                    import ui
                    v=ui.View(frame=(0,0,500,500))
                    t=ui.TextField(frame=(0,0,300,75))
                    v.add_subview(t)
                    def tfaction(textfield):
                    	'''when you change the textfield, and press return, this metjod is called'''
                    	print('textfield changed:', textfield.text )	
                    t.action=tfaction
                    v.present('sheet')
                    
                    

                    Button actions work in a similar way. Textfields/textviews also have additional delegate methods that trigger on changes (before pressing enter) -- see section in docs on delegates, and TextField and TextView delegate attribute.

                    You might also want more of a popup textfield, in which case the dialogs module or console.input_alert can act like a ui version of rAw_input

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