PyQtGraph - Closing Image View

PyQtGraph - Closing Image View

If you want to close an ImageView window in pyqtgraph, you can call the close method on the ImageView instance or its parent (if it's a part of a larger widget). The same method applies to any QWidget-derived object in PyQt.

Here's a simple example where we display an ImageView, and after 5 seconds, we automatically close it:

import sys import numpy as np import pyqtgraph as pg from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QTimer app = QApplication(sys.argv) # Generate dummy data data = np.random.random((100, 100)) # Create ImageView instance and display the data view = pg.ImageView() view.show() view.setImage(data) # Use a QTimer to close the view after 5 seconds def close_view(): view.close() QTimer.singleShot(5000, close_view) # 5000 milliseconds == 5 seconds sys.exit(app.exec_()) 

In the above example, the ImageView displays random data and is closed automatically after 5 seconds. If the ImageView is embedded within another widget, you'd call the close method on that parent widget (or whichever component you wish to close).


More Tags

markers android-textinputlayout auto-generate constants cdata dbf itemssource hex tomcat-jdbc core-image

More Programming Guides

Other Guides

More Programming Examples