欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pyqt添加啟動等待界面的操作

 更新時間:2021年03月17日 10:42:09   作者:“人生苦短”  
這篇文章主要介紹了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)文章

最新評論