Home  >  Article  >  Backend Development  >  How to add pictures in python

How to add pictures in python

尚
Original
2019-06-28 09:21:2524496browse

How to add pictures in python

1. Import image resources

Method 1: Import directly from the source image (the image is located in the images folder)

self.label1=QLabel(self)
self.label1.setPixmap(QPixmap(r"images/head.jpg"))
layout.addWidget(self.label1)
#或者 layout.addWidget(QLabel(self, pixmap=QPixmap("images/head.jpg")))

Method 2: Use qrc resources to import

1. First write the qrc file

<RCC>
<qresource>
<file>images/head.jpg</file>
<file>images/body.jpg</file>
</qresource>
</RCC>

2. Convert the qrc file into a py file

The conversion command is:

pyrcc5 res.qrc -o res_rc.py

3 , import res_rc.py: import res_rc

4, layout.addWidget(QLabel(self,pixmap=QPixmap(":/images/head.jpg")))

Note that you need to add: / symbol as a prefix.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to add pictures in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn