Python actual combat case, PyQt5 module, a quick viewing tool for epidemic information (with source code)

foreword

What I will introduce to you today is the Python epidemic information quick viewing tool. Here, I will give the code to the friends who need it, and give some tips.

Overview of PyQt

PyQt5 is the Python language implementation of the Qt framework, developed by Riverbank Computing, and is one of the most powerful GUI libraries. PyQt provides a well-designed collection of window controls, and each PyQt control corresponds to a Qt control, so the API interface of PyQt is very close to that of Qt, but PyQt no longer uses the QMake system and Q_OBJECT macro.

development tools

Python version: 3.8

Related modules:

PyQt5 module

csv module

time module

the code
ps: code pictures are for reference only

Environment build

Install Python and add it to the environment variable, and pip installs the required related modules.

Code

import sys
import base64
from PyQt5.Qt import *
from PyQt5.QtWidgets import *
from main_window import Ui_MainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView

class Covid19_viwer(QMainWindow):
    def __init__(self):
        super(Covid19_viwer, self).__init__()
        self.my_dict=eval(base64.decodebytes(b"""ezA6ICdodHRwczovL3ZvaWNlLmJhaWR1LmNvbS9hY3QvbmV3cG5ldW1vbmlhL25ld3BuZXVtb25p
YScsIDE6ICdodHRwczovL25ld3Muc2luYS5jbi96dF9kL3lpcWluZzAxMjEnLCAyOiAnaHR0cHM6
Ly93cC5tLjE2My5jb20vMTYzL3BhZ2UvbmV3cy92aXJ1c19yZXBvcnQvaW5kZXguaHRtbCcsIDM6
ICdodHRwczovL25ld3MucXEuY29tL3p0MjAyMC9wYWdlL2ZlaXlhbi5odG0jLycsIDQ6ICdodHRw
czovL3NhLnNvZ291LmNvbS9uZXctd2ViYWxsL3BhZ2Uvc2dzL2VwaWRlbWljJywgNTogJ2h0dHBz
Oi8vbmV3cy5pZmVuZy5jb20vYy9zcGVjaWFsLzd0UGxEU3pEZ1ZrJywgNjogJ2h0dHA6Ly93d3cu
dGNyai5jb20uY24veXF6dC9pbmRleC5jaHRtbCcsIDc6ICdodHRwOi8vc2hvdWppLjM2MC5jbi9m
eXlxZ2p4L2luZGV4Lmh0bWwnLCA4OiAnaHR0cHM6Ly9uY292LmR4eS5jbi9uY292aDUvdmlldy9w
bmV1bW9uaWEnLCA5OiAnaHR0cHM6Ly92aXAuamlhbnNoaWFwcC5jb20vcC9jb3ZpZDE5LW92ZXJz
ZWFzJywgMTA6ICdodHRwczovL2kuc25zc2RrLmNvbS91Z2MvaG90Ym9hcmRfZmUvaG90X2xpc3Qv
dGVtcGxhdGUvaG90X2xpc3QvZm9ydW1fdGFiLmh0bWwnLCAxMTogJ2h0dHA6Ly9tLnNpbm92aXNp
b24ubmV0L25ld3BuZXVtb25pYS5waHAnfQ=="""))
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.broswer=QWebEngineView()
        self.Layout = QHBoxLayout(self.ui.frame)
        self.Layout.setContentsMargins(0, 0, 0, 0)
        self.Layout.addWidget(self.broswer)
        self.broswer.load(QUrl(self.my_dict[0]))
        self.slot_init()

    def slot_init(self):
        self.ui.comboBox.currentIndexChanged[int].connect(self.change_engine)
        self.broswer.loadFinished.connect(self.change_state)
        self.broswer.loadProgress[int].connect(self.show_load_progress)

    @pyqtSlot(int)
    def change_engine(self,index):
        """
        改变引擎,触发
        :param index:
        :return:
        """
        self.ui.comboBox.setEnabled(False)
        self.broswer.load(QUrl(self.my_dict[index]))

    def change_state(self):
        """
        加载过程中,禁用comboBox
        :return:
        """
        self.ui.comboBox.setEnabled(True)

    def show_load_progress(self,p):
        """
        显示浏览器加载进度
        :param p:
        :return:
        """
        self.ui.statusBar.showMessage(str(p)+"%")
        if p==100:
            self.ui.statusBar.showMessage("完成",3000)

    def closeEvent(self,event):
        ret=QMessageBox.question(self,"退出","确定要退出吗?",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
        if ret==QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

if __name__ == '__main__':
    app=QApplication(sys.argv)
    ui=Covid19_viwer()
    ui.show()
    sys.exit(app.exec_())

Solve No module named 'PyQt5.QtWebEngineWidgets'

Specify the version of pyqt5, pip install pyqt5==5.10.1 The specified version is 5.10.1, this version supports built-in QtWebEngineWidgets, you can use it directly

Specific installation commands:

1. To install sip, enter in the command line window:

pip install sip==4.19.17 -i https://pypi.douban.com/simple

2. To install PyQt5, enter in the command line window:

pip install PyQt5==5.10.1 -i https://pypi.douban.com/simple

3. To install QScintilla, enter in the command line window:

pip install QScintilla==2.10.2 -i https://pypi.douban.com/simple

4. To install pyqt5-tools, enter in the command line window:

pip install pyqt5-tools==5.10.1.1.3 -i https://pypi.douban.com/simple

Result display

After running, the interface defaults to Baidu's engine
baidu

The following shows the results of switching the 360 ​​engine interface

360

at last

In order to thank the readers, I would like to share with you some of my recent favorite programming dry goods, to give back to every reader, and hope to help you.

There are practical Python tutorials suitable for beginners~

Come and grow up with Xiaoyu!

① More than 100+ Python e-books (mainstream and classic books should be available)

② Python standard library information (the most complete Chinese version)

③ Source code of reptile projects (forty or fifty interesting and classic hand-practicing projects and source codes)

④ Videos on basics of Python, crawlers, web development, and big data analysis (suitable for beginners)

⑤ Python Learning Roadmap (Farewell to Influential Learning)

Guess you like

Origin blog.csdn.net/Modeler_xiaoyu/article/details/128252622