pyqt添加启动等待界面
2024-08-31 13:34:40
一、实验环境
1.Windows7x64_SP1
2.anaconda3.7 + python3.7(anaconda集成,不需单独安装)
3.pyinstaller3.5 #使用pyinstaller3.0,打包时报错
二、实验步骤
1.resource.qrc文件中添加图片资源
<RCC>
<qresource>
<file alias="contacts.png">ico/contacts.png</file>
<file alias="exit.png">ico/exit.png</file>
<file alias="about.png">ico/about.png</file>
<file alias="config.png">ico/config.png</file>
<file alias="help.png">ico/help.png</file>
<file alias="xel.png">ico/xel.png</file>
<file alias="xel_small.png">ico/xel_small.png</file>
<file alias="magnifier.png">ico/magnifier.png</file>
<file alias="wait.png">ico/wait.png</file>
</qresource>
</RCC>
2.使用pyrcc5生成最新的resource.py文件,命令参考如下:
pyrcc5 -o resource.py resource.qrc
3.更改程序主文件
# -*- coding: utf-8 -*-
import os,sys,time,re
from PyQt5.QtWidgets import QMainWindow,QMessageBox
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication,QDialog,QSplashScreen
from PyQt5 import QtCore,QtGui
from untitled import Ui_MainWindow if __name__ == '__main__':
app = QApplication(sys.argv)
splash = QSplashScreen(QtGui.QPixmap(":/wait.png")) # 启动界面图片地址
splash.show() # 展示启动图片
app.processEvents() # 防止进程卡死
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/magnifier.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
tool = SmartBit_Tool()
tool.setWindowIcon(icon)
tool.show()
splash.finish(tool) # 关闭启动界面
sys.exit(app.exec_())
4.运行结果
运行exe文件发现,从双击exe文件至弹出启动界面图片,还是存在一定的延时!如何缩短这个延时,还需要继续研究,知道的童鞋也请告知!
5.提升运行速度
- 代码中不用的库,删除其导入语句
- 尽量使用from xxx import xxx,少用from xxx import *
- 使用pyinstaller打包文件,打包为一个文件夹
最新文章
- Ctrip Mydream
- 卓越精Forsk.Atoll.v3.3.2.10366无线网络
- 【RabbitMQ】RabbitMQ的一些基础概念
- task mysqld:26208 blocked for more than 120 seconds
- python中的内置函数getattr()
- TM1680的I2C的51例程
- C++ inline(内联什么时候使用)
- 【转】C数据存储(包括const存储在哪,C++不同部分我在文中用红字已指出)
- java线程(1)-线程同步
- NYOJ2括号配对问题
- 基于HTML5 Canvas的饼状图表实现教程
- css6种隐藏元素的方法
- Pycharm:书签的使用
- Python内置函数(65)——type
- redis源码解析(1):redisObject对象说明
- ALM 中查看某个 test 的更改 history 历史
- 干了这杯Java之transient关键字
- mysql登录1045错误时 修改登录密码
- [Codeforces743D][luogu CF743D]Chloe and pleasant prizes[树状DP入门][毒瘤数据]
- AngularJS转换请求内容
热门文章
- diango中的MTV——FBV/CBV以及装饰器的复用问题解决
- Windows 10 神州网信版
- redhat 6.5 更换yum源
- JVM-7-类加载机制
- (day68)Vue-CLI项目、页面跳转和传参、生命周期钩子
- koa2 从入门到进阶之路 (六)
- ASP.NET Core Web 应用程序系列(一)- 使用ASP.NET Core内置的IoC容器DI进行批量依赖注入(MVC当中应用)
- 谁说程序员不浪漫?Python导出微信聊天记录生成爱的词云图
- Java每日一面(Part1:计算机网络)[19/10/13]
- iOS事件传递和事件响应者链 20170810