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,

Static image view

pm = qt.QPixmap(“MatplotlibExample.png”)
imageWidget = qt.QLabel()

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.

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.