Forum Archive

Adding text to a TextView

robinsiebler112

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.

ccc

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

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

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

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

I just get "myview" is not defined.

Try "my_view" instead ;-)