• 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,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打包文件,打包为一个文件夹
  • 相关阅读:
    Java内存模型(JMM)
    线程安全问题的本质详解: 原子性、有序性、可见性
    Quartz实现分布式可动态配置的定时任务
    Java引用详解-StrongReference SoftReference WeakReference PhantomReference
    流行的报表生成工具-JXLS
    Java线程监控及中断
    IntelliJ IDEA 内存优化最佳实践
    Dapeng框架-开源高性能分布式微服务框架
    Scala实现Try with resources自动关闭IO
    Jvm启动,关闭及对应钩子
  • 原文地址:https://www.cnblogs.com/hester/p/11386956.html
Copyright © 2020-2023  润新知