# Adjusting window level with Python commands

**URL:** <https://discourse.slicer.org/t/adjusting-window-level-with-python-commands/12938>\
**Category:** Development\
**Created:** [August 11, 2020, 12:00am UTC](https://discourse.slicer.org/t/adjusting-window-level-with-python-commands/12938 "2020-08-11T00:00:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohan\_n](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rohan_n/32/78474_2.png) [@rohan\_n](https://discourse.slicer.org/u/rohan_n)\
**Post date:** [August 11, 2020, 12:00am UTC](https://discourse.slicer.org/t/adjusting-window-level-with-python-commands/12938/1 "2020-08-11T00:00:27Z")

</div>

Are there Python commands that do the same things as the various click and drag options of the Adjust Window level button? If so what is the syntax of these Python commands?  
Thanks,  
Rohan Nadkarni

---

<div class="post-metadata">

**Author:** ![mangotee](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@mangotee](https://discourse.slicer.org/u/mangotee)\
**Post date:** [August 11, 2020, 9:08am UTC](https://discourse.slicer.org/t/adjusting-window-level-with-python-commands/12938/2 "2020-08-11T09:08:32Z")

</div>

Hi there,  
if you have your volume node `nVol`, you can use these two lines:

```
nVol.GetDisplayNode().SetAutoWindowLevel(False)
nVol.GetDisplayNode().SetWindowLevel(window,level)

```

where window and level are float values.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [August 11, 2020, 1:28pm UTC](https://discourse.slicer.org/t/adjusting-window-level-with-python-commands/12938/3 "2020-08-11T13:28:58Z")

</div>

you can also do

```auto
def setAndObserveColorNode(nVol, colorMap = "PET-Heat"):
    """
    set observable in color node
    """
    displayNode = nVol.GetScalarVolumeDisplayNode()
    if displayNode is not None:
        colornodeID = slicer.util.getFirstNodeByName(colorMap).GetID()
        displayNode.SetAndObserveColorNodeID(colornodeID)
        # Refresh Window Level
        displayNode.AutoWindowLevelOff()
        displayNode.AutoWindowLevelOn()

```

That way you control the color map and refresh window level
