omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Trying to change label.text

    Pythonista
    3
    3
    89
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      philippe last edited by

      Hello everybody
      Labels have text attribute so I suppose it’s possible to change that but Labels don’t have action line in the GUI, no function to link with.
      Is there a way to access Labels and other windows in the view via ui ?

      cvp 1 Reply Last reply Reply Quote 0
      • brumm
        brumm last edited by

        Here you can find the manual for the ui module and a tutorial.

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @philippe last edited by cvp

          @philippe as usual, not sure I correctly understand your request.
          Try this code. It uses the name attribute of the label to be accessed in the button action

          import ui
          
          v = ui.View()
          v.frame = (0,0,400,400)
          v.background_color = 'lightgray'
          
          l = ui.Label(name='label')
          l.frame = (10,10,380,32)
          l.background_color = 'white'
          l.text = 'initial'
          v.add_subview(l)
          
          b = ui.Button()
          b.frame = (10,50,380,32)
          b.background_color ='white'
          b.title ='change label text'
          def b_action(sender):
          	b.superview['label'].text = 'new text' # b.superview is v, v['label'] refers thus to your label
          b.action = b_action
          v.add_subview(b)
          
          v.present('sheet')
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors