pyqt添加啟動等待界面的操作
一、實驗環(huán)境
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) # 關(guān)閉啟動界面 sys.exit(app.exec_())
4.運行結(jié)果
運行exe文件發(fā)現(xiàn),從雙擊exe文件至彈出啟動界面圖片,還是存在一定的延時!如何縮短這個延時,還需要繼續(xù)研究,知道的童鞋也請告知!
5.提升運行速度
代碼中不用的庫,刪除其導(dǎo)入語句
盡量使用from xxx import xxx,少用from xxx import *
使用pyinstaller打包文件,打包為一個文件夾
補充:PyQt5啟動畫面——等待程序啟動不用干瞪眼
PyQt的啟動畫面可以通過QSplashScreen類來快捷制作,支持透明圖片
import sys from PyQt5 import QtWidgets, QtGui # 對Qt部件的操作一般都要在創(chuàng)建Qt程序后才能進行 app = QtWidgets.QApplication(sys.argv) # 創(chuàng)建啟動界面,支持png透明圖片 splash = QtWidgets.QSplashScreen(QtGui.QPixmap('splash.png')) splash.show() # 可以顯示啟動信息 splash.showMessage('正在加載……') # 關(guān)閉啟動畫面 splash.close()
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
詳解python3安裝pillow后報錯沒有pillow模塊以及沒有PIL模塊問題解決
這篇文章主要介紹了python3安裝pillow后報錯沒有pillow模塊以及沒有PIL模塊問題解決,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04詳解Python 數(shù)據(jù)庫 (sqlite3)應(yīng)用
本篇文章主要介紹了Python標準庫14 數(shù)據(jù)庫 (sqlite3),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧。2016-12-12python utc datetime轉(zhuǎn)換為時間戳的方法
今天小編就為大家分享一篇python utc datetime轉(zhuǎn)換為時間戳的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-01-01Win10操作系統(tǒng)中PyTorch虛擬環(huán)境配置+PyCharm配置
本文主要介紹了Win10操作系統(tǒng)中PyTorch虛擬環(huán)境配置+PyCharm配置,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09如何通過Python的pyttsx3庫將文字轉(zhuǎn)為音頻
pyttsx3是一個開源的Python文本轉(zhuǎn)語音庫,可以將文本轉(zhuǎn)換為自然的人類語音,這篇文章主要介紹了如何通過Python的pyttsx3庫將文字轉(zhuǎn)為音頻,需要的朋友可以參考下2023-04-04