TutorialDoctor
Nov 08, 2014 - 10:34
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.