Forum Archive

having to do with classes and instants and scope - I don't know what to call it

bill.k

I have added a label (label1) in the Ui designer. Is there something I can preface my reference to it in the offending line so that it can be found?
What is the name of the main view when it is created by the Ui designer?

import ui

def button_tapped(sender):

  sender.title = 'Hello'
  label1.text = 'hello'      <-------------------------- causes error

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

dgelessus

ui.load_view returns a ui.View instance which corresponds to the root view of the .pyui file. A view's subviews can be accessed like the items of a dict (e. g. root["label1"]).

import ui

root = ui.load_view() # With no parameters it will load the view named like your script
root["label1"].text = "I am a happy label."

root.present("sheet")
bill.k

Thanks. That did just what I needed.