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.


    Change Button background color

    Editorial
    2
    3
    3195
    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.
    • Beginner101
      Beginner101 last edited by

      Hello again little helpers.

      I have another question for which I could not found any answer so far.
      maybe it is just not a problem at all but as a beginner I am at my limits. :)

      Problem:
      Have an UI with UI-Editor with buttons in it. Want to change background color of the tapped button.

      Tried:
      Python script within button action (button1->tapped). Now I just cannot figure out (and have not found any help in net or this forum - maybe I searched wrong) how to address that button1 attribute 'background_color'.

      I know that when I build he whole view by script I could 'instanciate' the buttons and have a handler there but how to do it when using UI editor?
      How to pick a certain button and change attributes?
      Tried it with 'sender.background_color = 'green' or 'UI.button1.background_color = 'green'

      all not working.

      therefore I have two questions:

      1. how to address an UI element from within scripts on views which were created with UIEditor?

      2. how to change the background color of a button by script?

      as always when I ask beginner questions: Thanks everyone for trying to help and spent your time on my problems! :)

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        From the docs:

        Behind the scenes, the controls of a Custom UI action correspond to Python objects from the ui module, so you can mix and match Python code with workflow-based UIs. When you have a custom UI and you want to get at the underlying view objects, you can do this with the workflow.get_view() method. This returns the root view of the currently-running Custom UI action, and you can use this to traverse the view hierarchy and make changes that wouldn’t be possible with workflow actions alone.

        As I understand it, if you launch your UI from the custom UI action rather than using ui.load_view from a Python action, then you have to use workflow.get_view(), and walk the heirarchy by names. I don't think you get sender.

        The other option I'd think would be to present the view from Python, in which case you can set Python actions which take a sender argument.

        1 Reply Last reply Reply Quote 0
        • Beginner101
          Beginner101 last edited by

          Hello back.

          Thank you for pointing my old brain in the right direction!

          You got it right and what you wrote was indeed the solution to my problem.
          I should have read the docs much more careful. :)

          Again, thank you very much for your quick help.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors