# Programmatically (python) define the values for the min and max of the slider in the volume widget (not the min-max of the window/level)

**URL:** <https://discourse.slicer.org/t/programmatically-python-define-the-values-for-the-min-and-max-of-the-slider-in-the-volume-widget-not-the-min-max-of-the-window-level/28916>\
**Category:** Support\
**Tags:** python\
**Created:** [April 14, 2023, 12:44pm UTC](https://discourse.slicer.org/t/programmatically-python-define-the-values-for-the-min-and-max-of-the-slider-in-the-volume-widget-not-the-min-max-of-the-window-level/28916 "2023-04-14T12:44:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonJones](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@RonJones](https://discourse.slicer.org/u/RonJones)\
**Post date:** [April 14, 2023, 12:44pm UTC](https://discourse.slicer.org/t/programmatically-python-define-the-values-for-the-min-and-max-of-the-slider-in-the-volume-widget-not-the-min-max-of-the-window-level/28916/1 "2023-04-14T12:44:02Z")

</div>

I am trying to define the minimum and maximum values of the slides in the volume widget (see screenshot - it is the widgets circled in red).

 ![WindowLevel slider - min-max](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/5/d5a371261f67791f151a5a32b7f84ce2ec2795da.png)

For clarity this is not the min-max of the WindowLevel.

Which widget do these elements belong to and how what is the most appropriate way to read/write them?

thanks

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [April 14, 2023, 5:47pm UTC](https://discourse.slicer.org/t/programmatically-python-define-the-values-for-the-min-and-max-of-the-slider-in-the-volume-widget-not-the-min-max-of-the-window-level/28916/2 "2023-04-14T17:47:27Z")

</div>

Once you have a qMRMLWindowLevelWidget object, you can use the `setMinMaxBounds` method.

```python
import SampleData
volume_node = SampleData.SampleDataLogic().downloadMRHead()
window_level_widget = slicer.qMRMLWindowLevelWidget() # creates a new window/level widget object
window_level_widget.setMRMLVolumeNode(volume_node)
window_level_widget.setMinMaxBounds(0,100)
window_level_widget.show()

```

You can also see discussion linked below about why you might use Window/Level values that are outside of the scalar range and why the values of -600 to 600 are chosen in the image you show.

> [@Improving qMRMLVolumeWidget range bounds](https://discourse.slicer.org/t/improving-qmrmlvolumewidget-range-bounds/17821/2):
>
> I have only used these widgets a few times in my life. Maybe partly because they are inconvenient, but mainly because I always set window/level visually (using the window/level mouse mode). Can you describe why and how do you use these widgets? Is there any workflow when you rely on setting these values numerically instead of visually? The popup makes sense in theory (it saves space and clicks), but I think the widget is quite confusing. slicer.qMRMLRangeWidget() solves the same task in a mu…

---

<div class="post-metadata">

**Author:** ![RonJones](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@RonJones](https://discourse.slicer.org/u/RonJones)\
**Post date:** [April 17, 2023, 2:04am UTC](https://discourse.slicer.org/t/programmatically-python-define-the-values-for-the-min-and-max-of-the-slider-in-the-volume-widget-not-the-min-max-of-the-window-level/28916/3 "2023-04-17T02:04:11Z")

</div>

Thanks. That works!

The other part I am having trouble working out is how to identify and access the existing WindowLevelWidget that is associated with PET Scalar volume.

---

<div class="post-metadata">

**Author:** ![RonJones](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@RonJones](https://discourse.slicer.org/u/RonJones)\
**Post date:** [April 26, 2023, 4:11am UTC](https://discourse.slicer.org/t/programmatically-python-define-the-values-for-the-min-and-max-of-the-slider-in-the-volume-widget-not-the-min-max-of-the-window-level/28916/4 "2023-04-26T04:11:41Z")

</div>

For reference below is how I worked out to access the existing window level widget.

Very interested to hear if there a better / cleaner approach. thanks.

```auto
ui = slicer.util.getModuleWidget("Volumes")
ui_children = slicer.util.childWidgetVariables(ui)
windowLevelWidget = ui_children.MRMLWindowLevelWidget
windowLevelWidget.setMinMaxBounds(0, 20)

```
