# Flash the background

**URL:** <https://forum.inductiveautomation.com/t/flash-the-background/19993>\
**Category:** Ignition\
**Created:** [October 5, 2018, 3:22pm UTC](https://forum.inductiveautomation.com/t/flash-the-background/19993 "2018-10-05T15:22:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [October 5, 2018, 3:22pm UTC](https://forum.inductiveautomation.com/t/flash-the-background/19993/1 "2018-10-05T15:22:10Z")

</div>

I would like to flash the background of a Text Field when that enter more characters then the max allowed. This is what I have right now:

```auto
import time
from java.awt import Color
TextField = event.source.parent.getComponent('Text Field')
startingColor = TextField.background
errorColor = Color(255,128,128)

if event.propertyName == 'text':
	print len(event.newValue)
	if len(event.newValue)>event.source.parent.MaxCharacters:
		event.source.text = ''
		TextField.background = errorColor
		sleep(5)
		TextField.background = startingColor

```

I found that this wont work becuase of the way the time function fires but can not think of another way to do it, any suggestions?

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [October 5, 2018, 3:29pm UTC](https://forum.inductiveautomation.com/t/flash-the-background/19993/2 "2018-10-05T15:29:28Z")

</div>

Definitely don’t call sleep from a GUI thread.

I would use an expression binding on the Text Field background instead. You could look at the current time in seconds and use a modulo operator to accomplish what you want.

Edit: Sounded like fun so I just went ahead and did it myself.

```auto
if((len({Root Container.Text Field.text}) > {Root Container.Text Field.MaxCharacters}) &&
(getSecond(now(1000)) % 2) ,
Color(255,128,128) , "White")

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 5, 2018, 4:16pm UTC](https://forum.inductiveautomation.com/t/flash-the-background/19993/3 "2018-10-05T16:16:56Z")

</div>

As a different approach, I changed the custom property to hold the length of the text. The style customizer than then be used to adjust setpoints and animations.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/53a2aa6a1e186d8d15d4fec7f733e5b6a6e09c3e.jpg)

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [October 5, 2018, 6:16pm UTC](https://forum.inductiveautomation.com/t/flash-the-background/19993/4 "2018-10-05T18:16:30Z")

</div>

Thank you both for you replies. going to try this now.

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [October 8, 2018, 10:44pm UTC](https://forum.inductiveautomation.com/t/flash-the-background/19993/5 "2018-10-08T22:44:07Z")

</div>

To expand on the sleep() thing, because I didn't know this and almost did a bad with the project I'm working on:

> [@Time.sleep function in Ignition](http://forum.inductiveautomation.com/t/time-sleep-function-in-ignition/10337/3):
>
> [quote=“dlaki”]Anyone here have tried to to use time.sleep function of time module in Ignition?[/quote]Nick hints at this, but let me be more explicit: Never, ever, use time.sleep or any other delay function in Ignition unless it is on its own asynchronous thread. Delays on the event dispatch thread (darn near everything in a client) will freeze the user interface for the duration of the delay. Just say no to any form of sleep. When you need delays, always use system.util.invokeLater() with …

That thread gives the reasons why you shouldn't use sleep() and a few workarounds
