# QT4 像素图(图片) > 原文: [https://pythonspot.com/qt4-pixmaps-images/](https://pythonspot.com/qt4-pixmaps-images/) 在本文中,我们将演示如何在 [PyQT](https://pythonspot.com/pyqt4/) 窗口中加载和显示图像。 我们可以使用 Pixmap 小部件在 [PyQT](https://pythonspot.com/pyqt4/) 窗口中显示图像。 ![PyQt4-load-image](img/77d7b4598127e8b587d29da009865dde.jpg) An image loaded in a PyQt4 window. ## 介绍 The constructor of Pixmap takes the image path as parameter: ```py pixmap = QPixmap(os.getcwd() + '/logo.png') ``` 该映像必须与程序位于同一目录中。 QPixmap 小部件支持 png 和 jpeg。 下面的示例代码。 ## PyQT 在 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. ```py import os import sys from PyQt4.QtGui import * # Create window app = QApplication(sys.argv) w = QWidget() w.setWindowTitle("PyQT4 Pixmap @ pythonspot.com ") # Create widget label = QLabel(w) pixmap = QPixmap(os.getcwd() + '/logo.png') label.setPixmap(pixmap) w.resize(pixmap.width(),pixmap.height()) # Draw window w.show() app.exec_() ``` [下载 PyQT 代码(批量收集)](https://pythonspot.com/python-qt-examples/) 结果: ![pyqt Pixmap](img/02ad7ee98094c1504dca8004682214e4.jpg) pyqt Pixmap