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.
UI TextField and TextView problems!
-
I keep trying to make programs that involve the UI module. But every time I use the UI module, I always end up needing to access what the user inputted in a TextField or TextView. I can't figure out how to do this.
Here is some of my code.
import ui def savefile(): text1 = ui.TextField("textfield1").text text2 = ui.TextView("textview1").text file = open(text1,"a") file.write(text2) file.close()
-
Use square brackets instead of parentheses...
text1 = ui.TextField["textfield1"].text text2 = ui.TextView["textview1"].text
-
ui.TextField() creates a completely new instance of a TextField. so there is nothing there yet! if you want the user to type something, you need to present a view first.
Presumably you have already created a textview, and presented it. your options are to save a reference to the field/textview, say as a global, or instance property of a custom class, or else give it aname
parameter, and search the main view usingrootview[’textview1']
where rootview is the variable for the parent view, and textfield1 is the default name for a textfield, assuming you only have one. -
Thank you for your help.