Forum Archive

How to reference textfield

Weecabin

I'm just starting to play with the ui module. I created a simple test program and ui with a textfield on it using the ui tool. I can't figure out how to get a reference to the text field so can access it from the code.

omz

The easiest way is to reference it by name, using the dict-like notation. When you load a view like this...

v = ui.load_view()

...and your UI file contains a text field with the name textfield1, you can get a reference to it like this:

# ...
textfield = v['textfield1']
Sebastian

You can access the different views with a dictionary like syntax, and you access them with their names. If you load the main view to a variable (let's call it root_view), you can access the textfield view like this: root_view['textfield1'] (textfield1 is the default name)

The textfield view has an additional variable named text, which of course stores the text data, and is accessed like this: root_view['textfield1'].text

I don't know if this is what you meant, but.. Oh well, I tried XD

Edit:
I was to late XD

Weecabin

Sorry for not responding, thought I'd receive an email when there was a response. I finally figured out both methods, but thanks for the reply!