pyqt添加启动等待界面的操作

这篇文章主要介绍了pyqt添加启动等待界面的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

一、实验环境

1.Windows7x64_SP1

2.anaconda3.7 + python3.7(anaconda集成,不需单独安装)

3.pyinstaller3.5 #使用pyinstaller3.0,打包时报错

二、实验步骤

1.resource.qrc文件中添加图片资源

   ico/contacts.png-600ico/exit.png-600ico/about.png-600ico/config.png-600ico/help.png-600ico/xel.png-600ico/xel_small.png-600ico/magnifier.png-600ico/wait.png-600

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-600"))   # 启动界面图片地址 splash.show()                      # 展示启动图片 app.processEvents()                   # 防止进程卡死 icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/magnifier.png-600"), 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 sys from PyQt5 import QtWidgets, QtGui # 对Qt部件的操作一般都要在创建Qt程序后才能进行 app = QtWidgets.QApplication(sys.argv) # 创建启动界面,支持png透明图片 splash = QtWidgets.QSplashScreen(QtGui.QPixmap('splash.png-600')) splash.show() # 可以显示启动信息 splash.showMessage('正在加载……') # 关闭启动画面 splash.close() 

以上为个人经验,希望能给大家一个参考,也希望大家多多支持html中文网。如有错误或未考虑完全的地方,望不吝赐教。

以上就是pyqt添加启动等待界面的操作的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python