# Change theme variable dynamically

**URL:** <http://forum.squareline.io/t/change-theme-variable-dynamically/3585>\
**Category:** How to\
**Created:** [July 19, 2024, 7:57pm UTC](http://forum.squareline.io/t/change-theme-variable-dynamically/3585 "2024-07-19T19:57:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablacho](http://forum.squareline.io/user_avatar/forum.squareline.io/pablacho/32/1437_2.png) [@pablacho](http://forum.squareline.io/u/pablacho)\
**Post date:** [July 19, 2024, 7:57pm UTC](http://forum.squareline.io/t/change-theme-variable-dynamically/3585/1 "2024-07-19T19:57:43Z")

</div>

### What do you want to achieve?

Change the color of an object that is themable

### What have you tried so far?

modifying the property with ui\_object\_set\_themeable\_style\_property

### Screenshot or video

- 

### Others

- \*\*SquareLine Studio version:_1.4.1_
- \*\*Operating system:_Windows 11_
- \*\*Target hardware:_ESP32_

I have several buttons with a border color that is themable (dark/light grey), and if they are ‘turned on’, they should change to dark/light blue depending on theme  
I have no issue doing that with ui\_object\_set\_themeable\_style\_property, but if I change themes, the color remains on the ‘blue’ shades even though i had changed the color back to grey earlier  
If I had not changed a particular button to blue, that button stays on the gray shades, so no issue there  
I think there is an issue with the rewrite of the property with ui\_object\_set\_themeable\_style\_property but i cannot find it!

---

<div class="post-metadata">

**Author:** ![Hermit](http://forum.squareline.io/user_avatar/forum.squareline.io/hermit/32/971_2.png) [@Hermit](http://forum.squareline.io/u/Hermit)\
**Post date:** [July 22, 2024, 10:35am UTC](http://forum.squareline.io/t/change-theme-variable-dynamically/3585/2 "2024-07-22T10:35:52Z")

</div>

The function ui\_object\_set\_themeable\_style\_property() is not intended to be used like that, i.e. the can’t be overridden by calling the function again. (It will create a new colliding entry.)  
If you really want to change the theme-colors in your LVGL code after exporting from SquareLine Studio, you should modify the style-variable’s value itself which was given as the 2nd argument of ui\_object\_set\_themeable\_style\_property(). (In case of SquareLine export these are elements of const arrays which can be a problem in your case, but themes are usually not to be modified afterwards by coders). Then setting the theme again or calling \_ui\_theme\_set\_variable\_styles() directly (or periodically) the change of the value will be sensed and the local style property (color) will be set.  
(Yet seeing your use-case makes us consider adding a function to delete themeable style-properties, not just to add them.)  
(I attached a projectfile which roundabout does what you describe above, just in case.)  
[ButtonColorThemeChanges.zip](http://forum.squareline.io/uploads/short-url/bgzY3FSEdQI2jpiY5hY7VFkXmIB.zip) (10.1 KB)

---

<div class="post-metadata">

**Author:** ![pablacho](http://forum.squareline.io/user_avatar/forum.squareline.io/pablacho/32/1437_2.png) [@pablacho](http://forum.squareline.io/u/pablacho)\
**Post date:** [July 22, 2024, 12:37pm UTC](http://forum.squareline.io/t/change-theme-variable-dynamically/3585/3 "2024-07-22T12:37:43Z")

</div>

Thanks a lot for your answer!  
I did what you suggested, added a new state (using LV\_STATE\_USER\_1) for the ‘ON’ state of the buttons, styled that with the themable colors, and finally changed states on the code. Worked like a charm.  
Thanks!!
