# How to show Monitor Number using the Label Display?

**URL:** <https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [July 17, 2024, 11:00pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360 "2024-07-17T23:00:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 17, 2024, 11:00pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/1 "2024-07-17T23:00:37Z")

</div>

Im trying to show the Monitor Number using the Label Display when opening the multi monitor fullscreen. Is there an expression that I can use?

---

<div class="post-metadata">

**Author:** ![simeonw](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@simeonw](https://forum.inductiveautomation.com/u/simeonw)\
**Post date:** [July 18, 2024, 2:19am UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/2 "2024-07-18T02:19:56Z")

</div>

You might find this post useful:

> [@Check what screen a client is open on](https://forum.inductiveautomation.com/t/check-what-screen-a-client-is-open-on/36970/17):
>
> I use something that you could possibly use for this purpose: a Global (shared) script, that implements functions WindowOpened and WindowClosed, to write who opened/closed what window to the audit\_events table a script on the visionWindowOpened event (and a corresponding script on the visionWindowClosed event) on every window in the project. I use this so I can track operator actions. I’m thinking you could query the most recent WindowOpened event in the audit\_events table, to see which windo…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 18, 2024, 2:43am UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/3 "2024-07-18T02:43:41Z")

</div>

There's no expression function solution, it'll require some amount of scripting.

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 18, 2024, 6:16pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/4 "2024-07-18T18:16:26Z")

</div>

Would you be able to guide me on how to accomplish this?

---

<div class="post-metadata">

**Author:** ![simeonw](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@simeonw](https://forum.inductiveautomation.com/u/simeonw)\
**Post date:** [July 18, 2024, 9:46pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/5 "2024-07-18T21:46:29Z")

</div>

The scripting documentation here is excellent:

> **[system.gui.getScreenIndex | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-gui/system-gui-getScreenIndex)**
>
> Returns an integer value representing the current screen index based on the screen from which this function was called.

---

<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:** [July 19, 2024, 4:44am UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/6 "2024-07-19T04:44:40Z")

</div>

> [@simeonw](#):
>
> [system.gui.getScreenIndex | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-gui/system-gui-getScreenIndex)

I suppose it depends on what the screen index is being used for. When I position windows in multi monitor setups, I want the screens to be sequentially indexed from left to right and top to bottom because my windows get covered up, and it makes it easier to find a specific instance in a specific monitor when tabbing. The problem is, screen indexes don't often work that way.

Here's a variation on a script I developed that will return an index based upon which monitor the parent window is in from left to right, top to bottom:

```python
# Import:
# ...GraphicsEnvironment for mapping the screens as they are in reality
# ...JFrame and SwingUtilities for getting the ancestor JFrame of a given component
from java.awt import GraphicsEnvironment
from javax.swing import JFrame, SwingUtilities

def getScreenIndex(component):
	# Get the screen bounds from the graphics environment and sort them from left to right, top to bottom
	screens = sorted([device.defaultConfiguration.bounds for device in GraphicsEnvironment.getLocalGraphicsEnvironment().screenDevices], key=lambda screen: (screen.x, screen.y))
	parentFrame = SwingUtilities.getAncestorOfClass(JFrame, component)
	for index, screen in enumerate(screens):
		if screen.contains(parentFrame.location()):
			return index

# Call the function from any component in any window and do something with the returned screen index
print getScreenIndex(event.source)

```

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 19, 2024, 1:32pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/7 "2024-07-19T13:32:30Z")

</div>

Hi Justin,

Thanks for the reply. I have a newbie question. Where do I actually put this script on. Also when you say print where does it go actually?

---

<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:** [July 19, 2024, 2:05pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/8 "2024-07-19T14:05:52Z")

</div>

> [@Melvin\_Miclat](#):
>
> Where do I actually put this script

Put it in the script library, and call it from anywhere.

**Print:**  
At the top of the designer, there is _Tools--\>Console_, or _Help--\>Diagnostic_ and select the console tab.

Either place will display the print statement.

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 19, 2024, 2:51pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/9 "2024-07-19T14:51:06Z")

</div>

I mean how do you direct the output to a component label text? I got the script and tested in the script console and see the output that i want. But i dont know how to direct that to show it on my Label component.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 19, 2024, 3:00pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/10 "2024-07-19T15:00:45Z")

</div>

Put it in the project library, and then use `runScript` to run it directly in a binding on the text property of your label:

> **[runScript | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/advanced/runScript)**
>
> Runs a single line of Python code as an expression.

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 19, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/11 "2024-07-19T15:39:02Z")

</div>

I already have a handle name that shows the correct Monitor Number. I just need to show it on different spot on my header. The reason for it is because when I open the windows full screen on startup the Monitor Number on top left is not visible. hopefully there is way to call the handle name to show as text on Label component.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e49517a260666ac7e4772c0e3c69582dc04000e4.png)

---

<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:** [July 19, 2024, 3:40pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/12 "2024-07-19T15:40:29Z")

</div>

The handle name is simply Monitor 1, Monitor 2, etc? If so, simply modify the return statement like so:

```python
return 'Monitor {}'.format(index)

```

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 19, 2024, 4:58pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/13 "2024-07-19T16:58:11Z")

</div>

the script that you provide that goes to the library I cant get it to work to into my intention here. it is giving me an event missing error.

---

<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:** [July 20, 2024, 12:39am UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/14 "2024-07-20T00:39:58Z")

</div>

> [@Melvin\_Miclat](#):
>
> it is giving me an event missing error

if you are using a `runscipt` binding instead of an event handler, you will need to use `self` for the argument instead of `event.source`

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 20, 2024, 1:00pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/15 "2024-07-20T13:00:38Z")

</div>

now it is giving a self not defined error.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [July 20, 2024, 1:03pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/16 "2024-07-20T13:03:30Z")

</div>

Can you show your expression on how you are calling the runScript?

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 20, 2024, 1:06pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/17 "2024-07-20T13:06:11Z")

</div>

```python
runScript("MonitorNumber.getScreenIndex()")

```

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 20, 2024, 1:08pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/18 "2024-07-20T13:08:01Z")

</div>

Here is the script in the library.

```python
# Import:
# ...GraphicsEnvironment for mapping the screens as they are in reality
# ...JFrame and SwingUtilities for getting the ancestor JFrame of a given component
from java.awt import GraphicsEnvironment
from javax.swing import JFrame, SwingUtilities

def getScreenIndex(component):
	# Get the screen bounds from the graphics environment and sort them from left to right, top to bottom
	screens = sorted([device.defaultConfiguration.bounds for device in GraphicsEnvironment.getLocalGraphicsEnvironment().screenDevices], key=lambda screen: (screen.x, screen.y))
	parentFrame = SwingUtilities.getAncestorOfClass(JFrame, component)
	for index, screen in enumerate(screens):
		if screen.contains(parentFrame.location()):
			return 'Monitor {}'.format(index)

# Call the function from any component in any window and do something with the returned screen index
print getScreenIndex(self)

```

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [July 20, 2024, 1:24pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/19 "2024-07-20T13:24:08Z")

</div>

You need to pass the "self" into the script.

> **[runScript | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/advanced/runScript)**
>
> Runs a single line of Python code as an expression.

Try this:

```python
runScript("MonitorNumber.getScreenIndex",0,"self")

```

Edited the call... removed the ()

---

<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:** [July 20, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/20 "2024-07-20T14:11:14Z")

</div>

`runScript()` cannot pass `self` as an argument when the first argument is a bare function. You have to use `runScript("someScript.someFunction(self)", 0)` and not pass any arguments, or use a component custom method (which implicitly gets `self`).

If you need more complex one-liners, use `objectScript()` from my Integration Toolkit.

[Next page](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360.md?page=2)
