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.
Understanding TextField
-
Once I place a TextField on the grid in the .pyui editor, what does the script in the .py file look like to retrieve the text input by the user? An example would be great.
I understand the action attribute that shows when you place a button on the grid but action does not show on a TextField, so I’m not sure how to make it call a function, like button, or store the user input.
Any help would be great.
-
Check out this topic. This probably has what you need.
GUI textfield example
https://forum.omz-software.com/topic/3609/gui-textfield-exampleThere's also a good example in the last post in this thread:
Basic UI Question
https://forum.omz-software.com/topic/3503/basic-ui-questionThese other topics have useful information.
textfield validation example
https://forum.omz-software.com/topic/2499/textfield-validation-example/2Ui.textfield drives slider
https://forum.omz-software.com/topic/3051/ui-textfield-drives-slider/8Pre fill Textfield
https://forum.omz-software.com/topic/2379/pre-fill-textfieldPlotting on a single screen with text fields
https://forum.omz-software.com/topic/1665/plotting-on-a-single-screen-with-text-fields/7How to set focus to textfield (2)
https://forum.omz-software.com/topic/1453/how-to-set-focus-to-textfield-2How to set the focus on a TextField?
https://forum.omz-software.com/topic/955/how-to-set-the-focus-on-a-textfield/4Tell cursor position in a TextField?
https://forum.omz-software.com/topic/1442/tell-cursor-position-in-a-textfieldHow to reference textfield
https://forum.omz-software.com/topic/863/how-to-reference-textfieldButton + Textfield Saving to Variable
https://forum.omz-software.com/topic/848/button-textfield-saving-to-variableabout 'TextField'
https://forum.omz-software.com/topic/740/about-textfieldI used the "Search" feature above to find these last few topics, but the first one I found using Google. I searched for "Pythonista TextField example" without the double quotes. That lead to this forum.
I'd have given an example myself, but while I've written several Pythonista programs now, I still haven't used a TextField. I learned a lot searching for this! Good luck.
-
@technoway WOW that is way more than I expected! Thank you so much for these references. I will dig in.
-
To summarize, there are essentially two ways of interacting with a
ui.TextField
:- Set its
action
attribute programmatically. This is currently not possible in the UI editor, but still easy to do: After loading the view, you can access the text field by its name (given in the UI editor) like this:
def text_field_action(sender): print('Text was entered:') # `sender` is the text field that caused the action. print(sender.text) v = ui.load_view('myui.pyui') # load the view tf = v['textfield1'] # Access subview by name tf.action = text_field_action # Important: No parentheses here! # ... v.present('sheet')
- By setting the text field's
delegate
. This is a lot more complex, but it allows you to control the behavior of the text field while text is entered (and not just afterwards, like with anaction
).
- Set its
-
@omz Thank you.