# How to hold the imageWidget display

**URL:** <https://discourse.slicer.org/t/how-to-hold-the-imagewidget-display/13246>\
**Category:** Support\
**Created:** [August 31, 2020, 10:19am UTC](https://discourse.slicer.org/t/how-to-hold-the-imagewidget-display/13246 "2020-08-31T10:19:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 31, 2020, 10:19am UTC](https://discourse.slicer.org/t/how-to-hold-the-imagewidget-display/13246/1 "2020-08-31T10:19:18Z")

</div>

Operating system: windows  
Slicer version: 4.11.0  
Expected behavior: show() to have the image shown  
Actual behavior: the image flashed and disappear

Hi all,  
I tried the following scripts,  
[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Using\_matplotlib](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Using_matplotlib)

# Static image view

pm = qt.QPixmap(“MatplotlibExample.png”)  
imageWidget = qt.QLabel()  
imageWidget.setPixmap(pm)  
imageWidget.setScaledContents(True)  
imageWidget.show()

if I input the above scripts into “Python Interactor”, I had the plot shown.  
But if I run it via a GUI click button, the plot seems flashed and disappeared right away. What’s wrong with my settings?

Thanks a lot.  
Best,  
Aiden

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 31, 2020, 2:03pm UTC](https://discourse.slicer.org/t/how-to-hold-the-imagewidget-display/13246/2 "2020-08-31T14:03:13Z")

</div>

Probably your variable goes out of scope so it is cleaned up. If you are writing a scripted module you can keep a reference to it in the `self` of the widget instance.

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 31, 2020, 2:10pm UTC](https://discourse.slicer.org/t/how-to-hold-the-imagewidget-display/13246/3 "2020-08-31T14:10:34Z")

</div>

😀Thanks a lot.  
Forget about this clearance rule.
