This article mainly introduces the download progress bar effect of PyQt5 in detail. It has certain reference value. Interested friends can refer to it.
The reason is because the company wants to develop an automatic login The assistant tool of a certain website is provided to customers and requires the use of selenium, so I chose the pyqt5 method to develop this C/S architecture client
In the process, I need to use the automatic update function, so I Write a download progress plug-in to share with everyone. My programming skills are a bit different, so don’t be offended.
Interface file UI_download.py
# -*- coding: utf-8 -*- from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.Qt import Qt class Ui_download(object): def setupUi(self, Dialog): Dialog.setWindowFlags(Qt.FramelessWindowHint) Dialog.setObjectName("Dialog") Dialog.resize(300, 56) Dialog.setFixedSize(Dialog.width(), Dialog.height()) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth()) Dialog.setSizePolicy(sizePolicy) Dialog.setSizeGripEnabled(True) self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint) self.gridLayout.setObjectName("gridLayout") self.progressBar = QtWidgets.QProgressBar(Dialog) self.progressBar.setProperty("value", 0) self.progressBar.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.progressBar.setObjectName("progressBar") self.gridLayout.addWidget(self.progressBar, 1, 0, 1, 1) self.label = QtWidgets.QLabel(Dialog) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.label.setText(_translate("Dialog", "客户端更新下载中...")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QDialog() ui = Ui_download() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_())
Implementation file download.py
# -*- coding: utf-8 -*- """ Module implementing Dialog. """ from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QDialog from PyQt5 import QtWidgets from Ui_download import Ui_download import os import sys import requests class downloadThread(QThread): download_proess_signal = pyqtSignal(int) def __init__(self, download_url, filesize, fileobj, buffer): super(downloadThread, self).__init__() self.download_url = download_url self.filesize = filesize self.fileobj = fileobj self.buffer = buffer def run(self): try: f = requests.get(self.download_url, stream=True) offset = 0 for chunk in f.iter_content(chunk_size=self.buffer): if not chunk: break self.fileobj.seek(offset) self.fileobj.write(chunk) offset = offset + len(chunk) proess = offset / int(self.filesize) * 100 self.download_proess_signal.emit(int(proess)) self.fileobj.close() self.exit(0) except Exception as e: print(e) class download(QDialog, Ui_download): """ 下载类实现 """ def __init__(self, download_url, auto_close=True, parent=None): """ Constructor @download_url:下载地址 @auto_close:下载完成后时候是否需要自动关闭 """ super(download, self).__init__(parent) self.setupUi(self) self.progressBar.setValue(0) self.downloadThread = None self.download_url = download_url self.filesize = None self.fileobj = None self.auto_close = auto_close self.download() def download(self): self.filesize = requests.get(self.download_url, stream=True).headers['Content-Length'] path = os.path.join("update", os.path.basename(self.download_url)) self.fileobj = open(path, 'wb') self.downloadThread = downloadThread(self.download_url, self.filesize, self.fileobj, buffer=10240) self.downloadThread.download_proess_signal.connect(self.change_progressbar_value) self.downloadThread.start() def change_progressbar_value(self, value): self.progressBar.setValue(value) if self.auto_close and value == 100: self.close() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) ui = download() ui.show() sys.exit(app.exec_())
A relatively common download module. When initializing the call, you only need to pass in the address to be downloaded. The download operation is asynchronous to prevent blocking the UI and ensure the program directory. There is an update directory under it. By default, I put the files to be updated under this directory. I hope you can point out the optimization areas.
The effect after running:
Related recommendations:
PyQt5 must learn the progress bar effect every day
PyQt5 Must Learn Every Day QSplitter Implements Window Separation
PyQt5 Must Learn Every Day Tool Tip Function
The above is the detailed content of PyQt5 implements download progress bar effect. For more information, please follow other related articles on the PHP Chinese website!

你可能遇到过智能手机屏幕出现绿色线条的问题,即使没见过,也一定在网络上看到过相关图片。那么,智能手表屏幕变白的情况你遇见过吗?4月2日,CNMO从外媒了解到,一名Reddit用户在社交平台上分享了一张图片,展示了三星Watch系列智能手表屏幕变白的情况。该用户写道:"我离开时正在充电,回来时就这样了,我尝试重启,但重启过程中屏幕还是这样。"三星Watch智能手表屏幕变白这位Reddit用户并未指明这款智能手表的具体型号。不过,从图片上看,应该是三星Watch5。此前,另一位Reddit用户也报告

pyqt5安装步骤:1、确保计算机上已安装Python和pip;2、在终端或命令提示符中输入“pip install PyQt5”命令来安装PyQt5;3、安装完成后,可以在Python脚本中导入PyQt5模块并开始使用;4、可以通过输入“pip install PyQt5.QtGui”命令来安装一些特定功能或组件;5、遇到任何问题,可以尝试升级pip和setuptools。

说起阿萨辛ASSASSIN,相信玩家们一定会想到《刺客信条》中的各位刺客大师,不仅身手了得,而且"躬身于黑暗、服务于光明"的信条,与国内知名机箱/电源/散热器品牌九州风神(DeepCool)旗下的阿萨辛ASSASSIN系列旗舰级风冷散热器不谋而合。最近,该系列的最新产品阿萨辛ASSASSIN4S重磅上线,"西装刺客,再进阶"为高级玩家带来全新的风冷散热体验。外观一览细节满满阿萨辛4S散热器采用双塔构造+单风扇内嵌设计,外面包覆立方体造型的整流罩,整体感极强,并提供白、黑两种配色可选,满足不同色系

随着春天的到来,万物复苏,一切都充满了生机与活力。在这个美好的季节里,如何为家居生活增添一抹别样的色彩?哈趣H2投影仪,以其精致的设计和超高的性价比,成为了这个春天里不可或缺的一道亮丽风景。这款H2投影仪小巧玲珑却不失时尚。无论是放在客厅的电视柜上,还是卧室的床头柜旁,都能成为一道亮丽的风景线。它的机身采用了奶白色的磨砂质地,这种设计不仅让投影仪的外观更显高级,同时也增加了触感的舒适度。米色仿皮纹材质,更是为整体外观增添了一抹温馨与雅致。这种色彩与材质的搭配,既符合现代家居的审美趋势,又能够融入

ITX平台以小巧的身形吸引了不少追求极致和独特美感的玩家,随着制程的提升和技术的进步,英特尔第14代酷睿和RTX40系显卡都可以在ITX平台中发挥实力,游戏玩家也对SFX电源有了更高的要求。游戏爱好者航嘉推出新的MX系列电源,在满足高性能需求的ITX平台中,MX750P全模组电源的定额功率高达750W,同时通过了80PLUS白金级认证。以下我们就带来这款电源的评测。航嘉MX750P全模组电源采用了简约时尚的设计理念,共有黑白两款供玩家选择,均采用磨砂表面处理,搭配银灰色和红色的字体有很好的质感,

在当下科技飞速发展的时代,笔记本电脑已经成为人们日常生活和工作中不可或缺的重要工具。对于那些对性能有高要求的玩家而言,拥有配置强大、性能出色的笔记本电脑才能满足其硬核需求。七彩虹隐星P15笔记本电脑凭借其卓越性能和令人惊艳的设计,成为了未来的引领者,堪称硬核笔记本的典范。七彩虹隐星P1524配备了13代英特尔酷睿i7处理器和RTX4060LaptopGPU,外观采用更时尚的宇宙飞船设计风格,同时在细节表现上也有出色表现。让我们先来了解一下这款笔记本的特点。至高搭载英特尔酷睿i7-13620H处理

一个可以自动分析PDF、网页、海报、Excel图表内容的大模型,对于打工人来说简直不要太方便。上海AILab,香港中文大学等研究机构提出的InternLM-XComposer2-4KHD(简写为IXC2-4KHD)模型让这成为了现实。相比于其他多模态大模型不超过1500x1500的分辨率限制,该工作将多模态大模型的最大输入图像提升到超过4K(3840x1600)分辨率,并支持任意长宽比和336像素~4K动态分辨率变化。发布三天,该模型就登顶HuggingFace视觉问答模型热度榜单第一。轻松拿捏

常见GUI框架 PyQt5:Qt是一个跨平台的 C++图形用户界面库。QT一度被诺基亚拥,后出售给芬兰的软件公司Digia Oyj。PyQt5是基于Digia公司Qt5的Python接口,由一组Python模块构成。PyQt5本身拥有超过620个类和6000函数及方法。在可以运行于多个平台,包括:Unix, Windows, and Mac OS。 Pyside6:Pyside是QT公司官方提供的Python包,上一版本为Pyside2,对应的是QT5,最新版命名规则进行了调整,更改为Pysid


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.