I have a TextView in my UI called "task_textview" How do I set the text for it in my main script? I tried task_textview.text = "Foo", but I get "global name 'task_textview' is not defined". I didn't 'define' my buttons anywhere but in the UI editor and they work just fine.
Forum Archive
Adding text to a TextView
robinsiebler112
Jul 30, 2014 - 10:45
ccc
Jul 29, 2014 - 13:41
You might need to address the text field relitive to the view that contains it...
class UserNameView(ui.View):
def __init__(self):
self.text_field = ui.TextField()
self.text_field.text = 'ccc'
Omega0
Jul 29, 2014 - 14:18
The view keeps a dictionary of it contained views by name. So you would do:
task_textview = myview['task_textview']
Then you can call the textview by the name task_textview.
robinsiebler112
Jul 29, 2014 - 16:01
I just get "myview" is not defined.
I used the UI editor to create it, so I am calling it like this:
ui.load_view("menu").present("sheet")
I had to change that to:
my_view = ui.load-_view('menu')
my_view.present('sheet')
self.task_view = my_view['task_textview']
Omega0
Jul 29, 2014 - 16:27
It's good practice to always assign things like a view to a variable, even if you're going to present it immediately. That way you can still call things like my_view.close() later.
ccc
Jul 30, 2014 - 10:45
I just get "myview" is not defined.
Try "my_view" instead ;-)