How to save user input from text field and use throughout script with ui?
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.
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.
@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.
@Taje, you can create a gist directly from your file in Pythonista, check the action ("wrench") menu. You get a link to your code.
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.
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.
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)
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.
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
console.input_alertcan act like a ui version of rAw_input