How to import images in python

藏色散人
Release: 2019-10-19 16:38:28
Original
18590 people have browsed it

How to import images in python

How to import images in python?

1. Import image resources

Method 1: Directly Import 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")))
Copy after login

Recommendation: "Python Tutorial"

Method 2: Use qrc resources to import

1. Write the qrc file first



images/head.jpg
images/body.jpg

Copy after login

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.

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

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!