How to hold the imageWidget display

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

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

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.

:grinning:Thanks a lot.
Forget about this clearance rule.