# 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:** 7\
**Page:** 2

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

</div>

10-4.

I was going from memory... I'm stuck in a hotel dealing with Crowdstrike aftermath at customer's sites.

---

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

</div>

> [@bschroeder](#):
>
> `"MonitorNumber.getScreenIndex`

I your library script really named MonitorNumber? I typically give my library scripts generic names, and then file many functions into them:

Example:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/5/455e394748c3ae8205e71eddc75a1a390ad4fa94.png)

Since my project has a generic library script called `windowScripts` and since this function involves determining which screen a **window** is in, I'm going to file this function somewhere in there.

> [@Melvin\_Miclat](#):
>
> `print getScreenIndex(self)`

This line needs to be deleted from the script library. It is the cause of your fault. Personally, I wouldn't use a run script expression for this. I would probably call this library script from the parent window's `internalFrameActivated` event handler if I felt like it needed to update if the window were moved to another screen.

```python
# Provide the appropriate relative path for the label component
label = event.source.getComponentForPath('Root Container.Label')

# Set the label's text property using the library script:
label.text = windowScripts.getScreenIndex(label)

```

If this were a one and done, then I would just use the label's propertyChange event handler like this:

```python
# Only occurs once when the component is first initialized
# Doesn't run in the designer unless preview mode started prior to opening the window
if event.propertyName == 'componentRunning':
	event.source.text = windowScripts.getScreenIndex(event.source)

```

**Edit:** Forgot to note that the `componentRunning` event won't fire in the designer unless preview mode is on prior to opening the window.

---

<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, 3:42pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/23 "2024-07-20T15:42:27Z")

</div>

It works now. I tried all of your suggestions and it all works but the numbering is off.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/db1c0ad160ad8c44c759a7bbf1a71ccb8cf980fa.png)

---

<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, 3:43pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/24 "2024-07-20T15:43:31Z")

</div>

here is my startup script in case I need to adjust it here.

```python
screensToOpen = {1:'AMINE/AMINE GAS TRAIN',
		2:'AMINE/AMINE INLET',
		3:'AMINE/AMINE SKID',
		4:'Paste your path to the screen you want to open on monitor 4 here'}
# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
  
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
system.nav.swapTo('AMINE/AMINE GAS TRAIN', {'Display':primaryScreenText})
system.nav.openWindow('Docked/Header')
system.nav.openWindow('Docked/Footer')

# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
    # unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
    screenIndex, screenWidth, screenHeight = screenDetails
    monitorNum = screenIndex + 1
    screenText = "This is Monitor %d" %monitorNum
    # Open an empty frame on the next monitor.
    # Assign a handle and apply the width/height for the monitor you are opening on
    handleName = "Monitor %d" %monitorNum
    system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
	
    # Open the Main Window on this new desktop and pass the parameters needed.
    system.nav.desktop(handleName).swapTo(screensToOpen[monitorNum],{'Display':screenText})
    system.nav.desktop(handleName).openWindow('Docked/Header')
    system.nav.desktop(handleName).openWindow('Docked/Footer')

```

---

<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, 3:48pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/25 "2024-07-20T15:48:32Z")

</div>

My Computer display setting is aligned to what the Label is showing. So I think the startup script needs to be aligned to my computer display setting.

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [July 20, 2024, 7:15pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/26 "2024-07-20T19:15:30Z")

</div>

1-Add a custom property called 'Display' on the root container of the window you're going to use to display your monitor number. From your screenshot it looks like it's your header.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f292a350fcd1f5d79718036f3b9599987f4fc5ed.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/540448bd15cd3ddb186f971b93a3106a0bae9d39.png)  
2-Bind your label to your new custom property.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/e/ceb1df85bc4157ac6c7a59d5f318d768c4dcdf7f.png)  
3-Modify your script so that you send you current monitor number to the correct window.

```python
screensToOpen = {1:'AMINE/AMINE GAS TRAIN',
		2:'AMINE/AMINE INLET',
		3:'AMINE/AMINE SKID',
		4:'Paste your path to the screen you want to open on monitor 4 here'}
# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
  
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
system.nav.swapTo('AMINE/AMINE GAS TRAIN', {'Display':primaryScreenText})
system.nav.openWindow('Docked/Header')
system.nav.openWindow('Docked/Footer')

# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
    # unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
    screenIndex, screenWidth, screenHeight = screenDetails
    monitorNum = screenIndex + 1
    screenText = "This is Monitor %d" %monitorNum
    # Open an empty frame on the next monitor.
    # Assign a handle and apply the width/height for the monitor you are opening on
    handleName = "Monitor %d" %monitorNum
    system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
	
    # Open the Main Window on this new desktop and pass the parameters needed.
    system.nav.desktop(handleName).swapTo(screensToOpen[monitorNum],{'Display':screenText})
    system.nav.desktop(handleName).openWindow('Docked/Header',{'Display':handleName})
    system.nav.desktop(handleName).openWindow('Docked/Footer')

```

---

<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, 8:27pm UTC](https://forum.inductiveautomation.com/t/how-to-show-monitor-number-using-the-label-display/93360/27 "2024-07-20T20:27:05Z")

</div>

Thank you this is working good now. This is the script.

```python
screensToOpen = {1:'AMINE/AMINE GAS TRAIN',
		2:'AMINE/AMINE INLET',
		3:'AMINE/AMINE SKID',
		4:'Paste your path to the screen you want to open on monitor 4 here'}

# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
			
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
system.nav.swapTo('AMINE/AMINE GAS TRAIN')
system.nav.openWindow('Docked/Header', {'Display':primaryScreenText})

# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
    # unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
    screenIndex, screenWidth, screenHeight = screenDetails
    monitorNum = screenIndex + 1
    screenText = "This is Monitor %d" %monitorNum
    # Open an empty frame on the next monitor.
    # Assign a handle and apply the width/height for the monitor you are opening on
    handleName = "Monitor %d" %monitorNum
    system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
	
    # Open the Main Window on this new desktop and pass the parameters needed.
    system.nav.desktop(handleName).swapTo(screensToOpen[monitorNum])
    system.nav.desktop(handleName).openWindow('Docked/Header', {'Display':screenText})

```

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