Forum Archive

Relationship between the .py and the .pyui files?

SteveIves

Hi,

Just getting started with using the Pythonista UI builder.

If I select 'Script with UI' and I call my file 'Test UI', then I get an empty Test UI.pyui file and a Test UI.py file with just an 'import ui' in it. Touching the button on the screen flip-flops between the 2 files.

Am I correct in thinking that my actual code goes in a separate source file (e.g. Test Code.py) in which I reference 'Test UI', or should my code go in the 'Test UI.py' file?

Thanks in advance for advice.

omz

Your code should typically be in the Test UI.py file. Assuming you created Test UI.py and Test UI.pyui, a minimal example for Test UI.py would be:

import ui

v = ui.load_view()
v.present('sheet')
Phuket2

Wow, I can help out with something, I think.
If you have a file 'x.py' and a file 'x.pyui' pythonista basically gives you a nice way to switch between the code view and the user interface. The files are only connected via the interface. No implicit connection is made.


# this file called x.py
import ui

if __name__ == '__main__':
    # this will work given you have a
    # file named x.pyui in the same dir
    v = ui.load_view()
    v.present()
# but you can easily load another view by specifying the file. The .pyui not required.
v = ui.load_view(another_view.pyui)
v.present()
Phuket2

Sorry, indentation off... I am still new.


# this file called x.py
import ui

if __name__ == '__main__':
    # this will work given you have a
    # file named x.pyui in the same dir
    v = ui.load_view()
    v.present()
# but you can easily load another view by specifying the file. The .pyui not required.
    v = ui.load_view(another_view.pyui)
    v.present()