Forum Archive

UI TextField and TextView problems!

AtomBombed

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()
ccc

Use square brackets instead of parentheses...

text1 = ui.TextField["textfield1"].text
text2 = ui.TextView["textview1"].text
JonB

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 a name parameter, and search the main view using rootview[’textview1'] where rootview is the variable for the parent view, and textfield1 is the default name for a textfield, assuming you only have one.

AtomBombed

Thank you for your help.