# Use progress bar from python

**URL:** <https://discourse.slicer.org/t/use-progress-bar-from-python/4343>\
**Category:** Development\
**Tags:** extensions-manager\
**Created:** [October 10, 2018, 12:39pm UTC](https://discourse.slicer.org/t/use-progress-bar-from-python/4343 "2018-10-10T12:39:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [October 10, 2018, 12:39pm UTC](https://discourse.slicer.org/t/use-progress-bar-from-python/4343/1 "2018-10-10T12:39:15Z")

</div>

The python code in my logic class can take some time to finish its calculations. I would like to add a progress bar in the UI. Is there any way to work with a progressbar info from python?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 10, 2018, 1:37pm UTC](https://discourse.slicer.org/t/use-progress-bar-from-python/4343/2 "2018-10-10T13:37:22Z")

</div>

You can use this convenience function for that

> <https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/util.py#L1136>

See example of usage here

> <https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMWidgets.py#L720>

---

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [October 11, 2018, 7:39am UTC](https://discourse.slicer.org/t/use-progress-bar-from-python/4343/3 "2018-10-11T07:39:34Z")

</div>

Thanks! My guess is that updating the progress object from inside the python logic is not good practice right. Do I have stick to widget space for this?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 11, 2018, 12:27pm UTC](https://discourse.slicer.org/t/use-progress-bar-from-python/4343/4 "2018-10-11T12:27:00Z")

</div>

In Python scripted modules, we typically add callback functions in the logic class to provide real-time feedback to widget (or any other component that uses the logic class). See for example how it is done in [DICOM Patcher module](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMPatcher/DICOMPatcher.py#L125).
