这篇教程pyqt添加启动等待界面的操作写得很实用,希望能帮到您。 一、实验环境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,refrom PyQt5.QtWidgets import QMainWindow,QMessageBoxfrom PyQt5.uic import loadUifrom PyQt5.QtWidgets import QApplication,QDialog,QSplashScreenfrom PyQt5 import QtCore,QtGuifrom 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打包文件,打包为一个文件夹 补充:PyQt5启动画面——等待程序启动不用干瞪眼 PyQt的启动画面可以通过QSplashScreen类来快捷制作,支持透明图片 import sysfrom PyQt5 import QtWidgets, QtGui# 对Qt部件的操作一般都要在创建Qt程序后才能进行app = QtWidgets.QApplication(sys.argv) # 创建启动界面,支持png透明图片splash = QtWidgets.QSplashScreen(QtGui.QPixmap('splash.png'))splash.show()# 可以显示启动信息splash.showMessage('正在加载……')# 关闭启动画面splash.close() 以上为个人经验,希望能给大家一个参考,也希望大家多多支持51zixue.net。如有错误或未考虑完全的地方,望不吝赐教。 Pyqt5 实现多线程文件搜索的案例 pyinstaller打包可执行文件,存放路径包含中文无法运行的解决方案 |