首先新建一个 .qrcimages.qrc
文件,内容格式如下:
<RCC>
<qresource prefix="/" >
<file>fire.png</file>
</qresource>
</RCC>
in the Terminal:
pyrcc4 -o images_qr.py images.qrc
inner_image.py
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2017/3/30 13:00
# @Author : otfsenter
# @File : inner_img.py
import sys
from PyQt4 import QtGui, QtCore
import images_qr
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
# 创建图片控件,使用图片的文件名作为参数
# The colon is important, it must be there
pixmap = QtGui.QPixmap(':/fire.png')
# 将图片控件放入标签控件中
lbl = QtGui.QLabel(self)
lbl.setPixmap(pixmap)
hbox.addWidget(lbl)
self.setLayout(hbox)
self.move(300, 200)
self.setWindowTitle('Pixmap')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()