当前位置:网站首页>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资源文件
这里在上面已经提前操作了。
最终脚本一切正常,可以在窗口中看到所导入的图片资源。
边栏推荐
- Gongfu developer community is settled! On July 30!
- Some time series modeling strategies (I)
- Cuda11.2 corresponding pytorch installation
- CONDA transfer project virtual environment essential skills +pip speed download too slow solution
- TB 117-2013美国联邦强制性法规
- 最后一篇博客
- "Weilai Cup" 2022 Niuke summer multi school training camp 2
- File depth monitoring strategy
- Spatiotemporal prediction 5-gat
- C#上位机开发—— 修改窗口图标和exe文件图标
猜你喜欢

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

MySQL教程:MySQL数据库学习宝典(从入门到精通)

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_ scale_ factor‘

测试面试题集-UI自动化测试

Cuda11.2 corresponding pytorch installation

JVM内存模型之Volatile关键字

Vs2019 export import configuration

J2 Redis之 AOF&RDB

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

这22个绘图(可视化)方法很重要,值得收藏!
随机推荐
ReentrantLock学习之公平锁过程
Typescript stage learning
SEO, client rendering ', server rendering, search engine understanding
Leetcode-138-copy linked list with random pointer
C # upper computer development - modify the window icon and exe file Icon
LeetCode笔记:Biweekly Contest 83
查看容器的几种方式
NLP 学习之路
EN 1504-6 products for protection and repair of concrete structures - reinforcement anchorage - CE certification
Leetcode notes: biweekly contest 83
How to solve the problem that win11 has been switched on after upgrading
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
J1:Redis为什么这么快+基本结构
conda+pytorch环境教程
最后一篇博客
2022 build enterprise level data governance system
通过源码深度分析线程池中Worker线程的执行流程
利用MySQL主从复制延迟拯救误删数据
Some time series modeling strategies (I)
Detailed tutorial on installing redis on Linux