当前位置:网站首页>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资源文件
这里在上面已经提前操作了。
最终脚本一切正常,可以在窗口中看到所导入的图片资源。
边栏推荐
- 安全测试与功能测试、渗透测试你知道有什么区别吗?
- Software process that testers must know
- 微信小程序插件--wxml-to-canvas(生成图片)
- Save gas chitoken usage
- (ICLR-2022)TADA! Time adaptive convolution for video understanding
- TB 117-2013 US Federal mandatory regulations
- Will 3R balanced financial products have risks? Is it risky?
- 文件深度监控策略
- TB 117-2013美国联邦强制性法规
- 洋葱集团携手OceanBase实现分布式升级,全球数据首次实现跨云融合
猜你喜欢

MySQL tutorial: MySQL database learning classic (from getting started to mastering)

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

用低代码搭建千人食品制造企业高效管理系统案例分析

LeetCode-138-复制带随机指针的链表

J2 Redis之 AOF&RDB

cuda11.2对应pytorch安装

还在用Xshell?你out了,推荐一个更现代的终端连接工具

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

JVM内存模型之Volatile关键字

配置服务器环境
随机推荐
客户案例 | 聚焦流程体验,助银行企业APP迭代
Introduce the difference between @getmapping and @postmapping in detail
Leetcode notes: Weekly contest 303
Selenium+Web自动化框架的Case
Sre person in charge of station B personally describes the multi activity disaster recovery construction after the 713 accident | takintalks share
Advantages of advanced anti DDoS IP in Hong Kong and which industries are suitable for use
ReentrantLock学习之---释放锁过程
Leetcode notes: biweekly contest 83
【YOLOv5】--详细版训练自己的数据集 保姆级学习日志记录 手把手教程
The difference between advanced anti DDoS server and advanced anti DDoS IP
千万不要随便把 Request 传递到异步线程里面 , 有坑 你拿捏不住,得用 startAsync 方法才行
Description of MDM separation of powers and classification and grading authority
Will 3R balanced financial products have risks? Is it risky?
高防服务器和高防IP的区别
Data Lake -- concept, characteristics, architecture and case overview
MapReduce (II)
MongoDB stats统计集合占用空间大小
J3:Redis主从复制
Spatiotemporal prediction 4-graph WaveNet
The inventory of chips in the United States is high, and the shipment of chips in China has increased rapidly and the import of 28.3 billion chips has been greatly reduced. TSMC has a showdown