# 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:** 1\
**Showing post:** 2

<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…

---

_[View the full topic](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)._
