Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Modifying UI Designer controls? [Solved]
-
How do I modify controls added in the UI Designer, via the python script?
The help says this:
- Add a button by tapping ‘+’.
- Drag it to the center of the canvas (it will snap to automatic alignment guides).
- Select “Edit Title” from the button’s context menu, and enter ‘Tap me!’ (or whatever you like).
- Finally, open the ‘Attributes...’ inspector (from the button’s menu, or by tapping the (i) button), and navigate to the “Frame / Auto-Resizing” section. Check all the margins (but not “Width” or “Height”). - This ensures that the button stays centered in its container.
- Still in the inspector, set the button’s action to button_tapped (just the function name, without any parentheses or parameters).
- For the code below to work as is, rename the UI file to “My UI”.
This is the code:
<pre>import ui
def button_tapped(sender):
sender.title = 'Hello'ui.load_view('My UI').present('sheet')</pre>
However, how would I change attributes of a label, or a slider etc, as a button action, or as a result of a tableView item being selected?
Delegates? If so, how?
An example would be helpful.
-
I found out how to do it from a Pythonista script, and made a basic example:
<pre>
import uidef button_tapped(sender):
label= sender.superview['label']
print label.textui.load_view().present('sheet')
</pre>Create a button with the name (not title) "label" for this code to work. Also, make its action "button_tapped" (no quotes).
Here is a test workflow.