当前位置:网站首页>PyQt5快速开发与实战 3.6 打包资源文件
PyQt5快速开发与实战 3.6 打包资源文件
2022-07-26 18:25:00 【Ding Jiaxiong】
PyQt5快速开发与实战
文章目录
3. 第3章 Qt Designer的使用
3.6 打包资源文件
使用PyQt5生成的应用程序引用图片资源主要有两种方法:
- 将资源文件转换为Python文件,然后引用Python文件
- 在程序中通过相对路径引用外部图片资源
3.6.1 使用 Qt Designer 加载资源文件
新建资源文件apprcc.qrc

新建一个简单窗体

资源编辑中

添加资源

apprcc.qrc文件自动添加了代码

3.6.2 在窗体中使用资源文件
添加一个label标签,更改pixmap属性

ui转py

调用模块 CallMainWin02.py

这里要先把.qrc文件也转为py文件
然后调用

import sys
from PyQt5.QtWidgets import QApplication,QMainWindow
from MainWin02 import Ui_Form
class MyMainWindow(QMainWindow,Ui_Form):
def __init__(self,parent = None):
super(MyMainWindow,self).__init__(parent)
self.setupUi(self)
if __name__ == '__main__':
from pyqt5_plugins.examples.exampleqmlitem import QtCore
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
myWin = MyMainWindow()
myWin.show()
sys.exit(app.exec_())
运行

3.6.3 转换资源文件


3.6.4 导入.py资源文件
这里在上面已经提前操作了。
最终脚本一切正常,可以在窗口中看到所导入的图片资源。
边栏推荐
- Several ways to view containers
- PMP practice once a day | don't get lost in the exam -7.26 (including agility + multiple choices)
- 配置服务器环境
- EN 1504-6 products for protection and repair of concrete structures - reinforcement anchorage - CE certification
- Using MySQL master-slave replication delay to save erroneously deleted data
- C # upper computer development - modify the window icon and exe file Icon
- 服务器内存故障预测居然可以这样做
- ReentrantLock学习之---基本属性
- Pads draw 2.54mm row needle
- To add a composite primary key
猜你喜欢

What is a server cluster? What are the advantages of overseas server clusters?

Article 7:exited on desktop-dff5kik with error code -1073741511

J3: redis master-slave replication

Pychart loads CONDA to create a pytorch virtual environment and reports an error. It is normal on the CONDA command line

Sre person in charge of station B personally describes the multi activity disaster recovery construction after the 713 accident | takintalks share

关于接口测试你想知道的都在这儿了

Test interview question set UI automated test

C语言-入门-语法-字符串(十一)

C#创建及读取DAT文件案例

数据湖--概念、特征、架构与案例概述
随机推荐
测试人员必须知道的软件流程
Software process that testers must know
C language - Introduction - syntax - string (11)
手机app测试用例怎么写?手机app测试点有哪些?
"Weilai Cup" 2022 Niuke summer multi school training camp 1
从6月25日考试之后,看新考纲如何复习PMP
How to protect e-commerce websites from network attacks?
A case study of building an efficient management system for a thousand person food manufacturing enterprise with low code
Detailed tutorial on installing redis on Linux
Spatiotemporal prediction 4-graph WaveNet
Mathematical basis of deep learning
Tensorflow-GPU 1.15安装
Pads draw 2.54mm row needle
关于接口测试你想知道的都在这儿了
2022搭建企业级数据治理体系
2022 build enterprise level data governance system
Aof & RDB of J2 redis
Customer cases | focus on process experience to help bank enterprise app iteration
Reentrantlock learning --- basic method
File depth monitoring strategy