# Change container back to default without button press

**URL:** <http://forum.squareline.io/t/change-container-back-to-default-without-button-press/3789>\
**Category:** How to\
**Created:** [September 10, 2024, 8:05am UTC](http://forum.squareline.io/t/change-container-back-to-default-without-button-press/3789 "2024-09-10T08:05:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patsjemoe](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/e36b37/32.png) [@Patsjemoe](http://forum.squareline.io/u/Patsjemoe)\
**Post date:** [September 10, 2024, 8:05am UTC](http://forum.squareline.io/t/change-container-back-to-default-without-button-press/3789/1 "2024-09-10T08:05:57Z")

</div>

I have a container , with a picture that changes color when I push a button. This works fine in Arduino IDE/esp32 with : \_ui\_state\_modify(ui\_Container1, LV\_STATE\_USER\_1, \_UI\_MODIFY\_STATE\_TOGGLE);  
But I want to go back to my default setting without pressing the button again, but after a defined time.

I tried to put lv\_obj\_set\_style\_bg\_img\_src(ui\_Container1, &ui\_img\_doorbell\_groen\_20x20n\_png, LV\_PART\_MAIN | LV\_STATE\_DEFAULT); , but this is not working.

### Others

- **SquareLine Studio version: 1.4.2**
- windows 10
- Target : Arduino IDE with ESP32

Thanks in advance  
best regards  
Ludo

---

<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:** [September 12, 2024, 7:31pm UTC](http://forum.squareline.io/t/change-container-back-to-default-without-button-press/3789/2 "2024-09-12T19:31:51Z")

</div>

You can use \_ui\_state\_modify() in the timed callback too, to change/toggle the original state back I guess. (But maybe I don’t get correctly what you want to achieve, because in the first part you say you change to the ‘color’ of USER\_1 state , but in the second part you want to change back to an original image.)  
Anyway, after you change to USER\_1 state, it overrides the DEFAULT state, that’s why you don’t see a change, as the widget is still in USER\_1 state. So to change the image in USER\_1 state (if you want that), the last LV\_STATE\_DEFAULT should be changed to LV\_STATE\_USER\_1 to see any change at that state.

---

<div class="post-metadata">

**Author:** ![Patsjemoe](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/e36b37/32.png) [@Patsjemoe](http://forum.squareline.io/u/Patsjemoe)\
**Post date:** [September 13, 2024, 7:10am UTC](http://forum.squareline.io/t/change-container-back-to-default-without-button-press/3789/3 "2024-09-13T07:10:32Z")

</div>

Hi, thank you for your feedback.  
Sorry for the confusing… I have 2 images, both different color, so when I said change color, it really was the image.  
When I use the exported files, I still have the problem that my event is not working in Arduino ide with esp32-2432s028. Nothing happens when I push the button.  
Only \_ui\_state\_modify(ui\_Container1, LV\_STATE\_USER\_1, \_UI\_MODIFY\_STATE\_ADD);  
lv\_img\_set\_src(ui\_Image1, &ui\_img\_bell\_rood20x20n\_png); that I put in arduino loop, gave a change from default green image to red image. But adding a delay of 1sec (up to 5 tried) and then \_ui\_state\_modify(ui\_Container1, LV\_STATE\_DEFAULT, \_UI\_MODIFY\_STATE\_ADD); even made the application not change from green to red in the first place.  
I am sorry, but do not understand the second part : after you change to USER\_1 state, it overrides the DEFAULT state, that’s why you don’t see a change, as the widget is still in USER\_1 state…my default is green image, if I go to red image (user1), it should show red …isn;t it ?  
Can you advise what I have to do to :

1. Be able to use the squareline exported files in arduino IDE /confirm that the button pressed should work in arduino, just as in your simulator./or what to do to make it work.
2. what do I need to do in the event section to go from green image to red image on pressed, and from red image to green image on release button1 ? (I changed in the mean time from just image instead of image in a container).  
Note : In the exported squareline files, in the loop, there is no lv\_task\_handler();. from chatgpt, I learned that this is required to process GUI events…is that correct ? If correct, is there a reason why it is not put into the .ino file ?  
thanks and regards  
Ludo

---

<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:** [September 13, 2024, 9:46am UTC](http://forum.squareline.io/t/change-container-back-to-default-without-button-press/3789/4 "2024-09-13T09:46:16Z")

</div>

-The button event that toggles USER\_1 state should work in Arduino if it works in SquareLine Studio. (It’s just not pit into ui\_events.c, but ui.c)  
-I think you should read the ‘States’ section in [LVGL document about objects](https://docs.lvgl.io/8.3/overview/object.html), that explains in details that there can be more states enabled, DEFAULT is the state, and other states can override it until they’re removed. So you should remove LV\_STATE\_USER\_1 to get the original red color/image back.  
-Presence of lv\_task\_handler in he loop is required for LVGL to process events, update graphic when needed, etc.
