Change Button background color
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. :)
Have an UI with UI-Editor with buttons in it. Want to change background color of the tapped button.
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:
how to address an UI element from within scripts on views which were created with UIEditor?
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! :)
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.
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.