Forum Archive

Modifying UI Designer controls? [Solved]

TutorialDoctor

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:

import ui

def button_tapped(sender):
    sender.title = 'Hello'

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

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.

TutorialDoctor

I found out how to do it from a Pythonista script, and made a basic example:

import ui

def button_tapped(sender):
    label= sender.superview['label']
    print label.text

ui.load_view().present('sheet')

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.