pyqt display image
Python hosting: Host, run, and code Python in the cloud!
In this article we will demonstrate how to load and display images in an PyQT window. We can display images in a PyQT window using the Pixmap widget.

Related course:
Introduction
The constructor of Pixmap takes the image path as parameter:
pixmap = QPixmap(os.getcwd() + '/logo.png') |
This image needs to be in the same directory as your program. The QPixmap widget supports png and jpeg. Example code below.
PyQT load image in Pixmap
We create a standard QWidget as we have done before. Then we add the QPixmap widget inside which will load the image. The Pixmap is attached to a label which is drawn to the screen.
import os |
Download PyQT Code (Bulk Collection)
Result:

Posted in QT4
Leave a Reply:
At least on Windows - this hangs without response to ^C if logo does not exist.
Added simple error check
Hi Jeremy, after changing to the correct quotes and changing the \\ to /, this program works fine under Linux.
Did you try with other image formats such as JPG or GIF? Make sure the quotes are correct.