# Change the text in a label on a time delay

**URL:** <https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [August 26, 2022, 9:38pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520 "2022-08-26T21:38:49Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_Whorton](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@Jay\_Whorton](https://forum.inductiveautomation.com/u/Jay_Whorton)\
**Post date:** [August 26, 2022, 9:38pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/1 "2022-08-26T21:38:49Z")

</div>

I have a label that has a text value of “READY TO SEND”

It changes the value to “SENT” on a button press in the same view.

How do I set a 5 second timer to change it back to “READY TO SEND”??

Edit: This is a perspective project. Sorry for the lack of detail, was writing this as I was walking out the door. I will give these a try on Monday. Thanks everyone for you input!

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 26, 2022, 11:20pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/2 "2022-08-26T23:20:20Z")

</div>

This approach should work if added to your button’s onActionPerformed event:

```auto
def endSequence ():
	event.source.parent.getComponent('yourLabel').text = "READY TO SEND"
system.util.invokeLater(endSequence, 5000)

```

Edit: Assuming this is Vision

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 27, 2022, 12:28am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/3 "2022-08-27T00:28:34Z")

</div>

You’re assuming Vision.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 27, 2022, 12:29am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/4 "2022-08-27T00:29:45Z")

</div>

OP stated “view”, so I would assume Perspective. Probably best if the OP clarified.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 27, 2022, 12:30am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/5 "2022-08-27T00:30:57Z")

</div>

Ah I didn’t see that. Invoke later doesn’t work with perspective I didn’t think 🤔 I could be wrong  
Or rather, it’s unnecessary since perspective scripts don’t lock up the gui

 ![Screenshot_20220827-100226_Chrome](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/4364980e5919922e9c492a46bb04549200f8fdc2.jpeg)

Scope is vision

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 27, 2022, 12:35am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/6 "2022-08-27T00:35:19Z")

</div>

@nminchin: You are correct; I assumed vision. I didn’t make the connection to the word ‘view,’ so @jlandwerlen is probably correct that this is a perspective question.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 27, 2022, 12:36am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/7 "2022-08-27T00:36:57Z")

</div>

With the number of times people ask questions without specifying or implying, the label should be made mandatory. Or maybe a category should be added for which module you’re using

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 27, 2022, 1:20am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/8 "2022-08-27T01:20:21Z")

</div>

Assuming this is Perspective, this approach should work if added to the end of the button’s onActionPerformed event:

```auto
import time	
time.sleep(5)
self.getSibling("yourLabel").props.text = "READY TO SEND"

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 27, 2022, 3:16am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/9 "2022-08-27T03:16:19Z")

</div>

I’m always loathe to use a sleep. I don’t have a solid enough understanding why though, especially in an instance like this where it seems logical. I assume if you have many of these running in a lot of places it could cause a large number of threads to be locked. But if it’s a once off or few clients, then it should be OK. You should however plan for scaling your project if necessary.

~~The~~ an alternative is to set a custom prop null default to the current time when the button is pressed and use another prop bound to now(1000) if the time is non-null value. Then using a change event script, check if the time difference is greater than 5s and then set the set time to none.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 27, 2022, 3:21am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/10 "2022-08-27T03:21:04Z")

</div>

You could also drive the nail with a sledge hammer and use `java.util.Timer` and `java.util.TimerTask`.

A little overkill, but avoids the sleep.

Personally I like the alternative you supplied.

---

<div class="post-metadata">

**Author:** ![limwl](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/limwl/32/23882_2.png) [@limwl](https://forum.inductiveautomation.com/u/limwl)\
**Post date:** [September 1, 2022, 6:09am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/11 "2022-09-01T06:09:47Z")

</div>

A guy in Stack overflow explain well on the disadvantage of sleep. Using scheduling python script will be much better.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f412382b0a3aa70a6cfc8e06353f0f3e5c72b0f.png)  
source:[v](https://stackoverflow.com/questions/57205423/is-there-any-reason-i-shouldnt-use-the-time-sleep-command-to-make-my-program)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 1, 2022, 11:36am UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/12 "2022-09-01T11:36:02Z")

</div>

Jython is substantially different from CPython, and even moreso embedded in Ignition, so those points don’t really apply.

The biggest problems with `sleep()` _ **in Ignition** _ are:

- using it on the foreground thread in a Vision Client freezes the client User Interface completely.

- using it in gateway tag events (on the tag) ties up a workqueue thread needed to process other tags’ events. Three such sleeps simultaneously will halt all other tags’ event processing.

- using it in events (in a project) ties up that event’s handler, delaying processing repeat events (or other tags in a tag change event’s monitor list).

The first of these is well-known, and causes developers to use asynchronous threads to perform tasks with sleep(). But the temptation to access/manipulate a Vision Client UI from that background thread seems to be irresistable, leading to occasional complete client lockups.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 1, 2022, 1:38pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/13 "2022-09-01T13:38:11Z")

</div>

I’ve done quite a few apps in C#, and the sleep command behaves the same way, so our superstitions are well justified, but for the sake of this thread, the sleep command launched from his button to delay a label text change in a Perspective view will not lock up anything. Due to the simplicity of implementation, this is one occasion where it makes sense to use it.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 1, 2022, 2:00pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/14 "2022-09-01T14:00:31Z")

</div>

This is a crude example, uses expression and change script.

```auto
{
  "custom": {},
  "params": {},
  "props": {},
  "root": {
    "children": [
      {
        "events": {
          "component": {
            "onActionPerformed": {
              "config": {
                "script": "\tself.getSibling(\"Label\").custom.textTime \u003d system.date.now()"
              },
              "scope": "G",
              "type": "script"
            }
          }
        },
        "meta": {
          "name": "Button"
        },
        "position": {
          "height": 34,
          "width": 80,
          "x": 133,
          "y": 140
        },
        "type": "ia.input.button"
      },
      {
        "custom": {
          "textTime": {
            "$": [
              "ts",
              192,
              1662040678099
            ],
            "$ts": 1662040678098
          }
        },
        "meta": {
          "name": "Label"
        },
        "position": {
          "height": 32,
          "width": 234,
          "x": 262,
          "y": 142
        },
        "propConfig": {
          "custom.testReset": {
            "binding": {
              "config": {
                "expression": "(secondsBetween({this.custom.textTime}, now()) \u003e\u003d 5)"
              },
              "type": "expr"
            },
            "onChange": {
              "enabled": null,
              "script": "\tif currentValue.value:\n\t\tself.props.text \u003d \u0027Text reset\u0027\n\telse:\n\t\tself.props.text \u003d \u0027Button was pushed\u0027"
            }
          }
        },
        "props": {
          "text": "Text reset"
        },
        "type": "ia.display.label"
      }
    ],
    "meta": {
      "name": "root"
    },
    "type": "ia.container.coord"
  }
}

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 1, 2022, 2:53pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/15 "2022-09-01T14:53:39Z")

</div>

> [@justinedwards.jle](#):
>
> the sleep command launched from his button to delay a label text change in a Perspective view will not lock up anything

This is true, however, I avoid it everywhere so I don't end up using it where I shouldn't.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 1, 2022, 3:10pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/16 "2022-09-01T15:10:21Z")

</div>

One question on this to the sleep expert @pturmel - the example given is innocuous enough and with a handful of clients I’m sure there’s no real damage that will be done.

But given this is perspective and everything runs on a gateway, I would assume there’s a threshold where if too many clients were on this page with the sleep script, it could cause _some_ problems. Is that right or would this always be ok regardless of client load? Just asking for my own edification.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 1, 2022, 3:42pm UTC](https://forum.inductiveautomation.com/t/change-the-text-in-a-label-on-a-time-delay/63520/17 "2022-09-01T15:42:39Z")

</div>

Perspective uses an unbounded thread pool workqueue. So a sleeping Perspective thread is not blocking anything else. It just wastes RAM and a few extra CPU cycles of overhead.

It does make reviewing the thread status on the gateway a nightmare, and makes thread dumps exceedingly slow. But it doesn’t kill functionality abruptly like the cases I list.
