主頁 > 知識庫 > pyqt添加啟動等待界面的操作

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

熱門標簽:百度AI接口 電話運營中心 呼叫中心市場需求 客戶服務 語音系統(tǒng) 硅谷的囚徒呼叫中心 企業(yè)做大做強 Win7旗艦版

一、實驗環(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)                   # 關閉啟動界面
  sys.exit(app.exec_())

4.運行結(jié)果

運行exe文件發(fā)現(xiàn),從雙擊exe文件至彈出啟動界面圖片,還是存在一定的延時!如何縮短這個延時,還需要繼續(xù)研究,知道的童鞋也請告知!

5.提升運行速度

代碼中不用的庫,刪除其導入語句

盡量使用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('正在加載……')
# 關閉啟動畫面
splash.close() 

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • python GUI庫圖形界面開發(fā)之PyQt5窗口控件QWidget詳細使用方法
  • python GUI庫圖形界面開發(fā)之PyQt5線程類QThread詳細使用方法
  • python GUI庫圖形界面開發(fā)之PyQt5布局控件QVBoxLayout詳細使用方法與實例

標簽:山西 濟南 長沙 喀什 安康 崇左 山西 海南

巨人網(wǎng)絡通訊聲明:本文標題《pyqt添加啟動等待界面的操作》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266