Forum Archive

Trying to create a simple script with UI Designer

Bob Walance

Greetings,

I'm brand new to Pythonista and I want to use UI Designer to create a form.

Within UI Designer, I have added a LABEL box to the file 'My UI.pyui', and have changed the LABEL box's 'Name' attribute to 'Connect_label'.

All I want to do is to change the LABEL box's TEXT attribute to "Fred", but I get an error:
"name 'Connect_label' is not defined'

I would have thought that by loading the "My UI" form (and that works) that I could have access to and modify the LABEL box's attributes. Do I need to add something else in the code?

Here's the code:


import ui
ui.load_view('My UI').present('sheet')

Connect_button.text = 'Fred'


lukaskollmer

You can access a views ui elements using the subscript syntax:

view = ui.load_view()
view["connect_label"].text = "text"
view.present("sheet")
Bob Walance

LK,

That causes even more errors.

If, just after:
ui.load_view('My UI').present('sheet')
I add:
view = ui.load_view()

I get this error:
[Errno 2] No such file or directory...

Bob

lukaskollmer

1) you have to replace the ui.load_view().present() line with my code
2) your pyui file needs to have the same file name as the script you're calling load_view in

Bob Walance

Lukas,

I got it. That works! Thanks.

May you live to be one-thousand years old, sir.

Bob