Frontend Development 7 min read

Building a Quick COVID‑19 Information Viewer with PyQt5 (≈100 Lines of Code)

This tutorial demonstrates how to create a lightweight desktop application using PyQt5 and PyQtWebEngine that fetches and displays the latest COVID‑19 information from multiple web sources, includes engine switching, and provides the full source code for a 100‑line implementation.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Building a Quick COVID‑19 Information Viewer with PyQt5 (≈100 Lines of Code)

Introduction

With the year ending and public attention on the pandemic increasing, this article shows how to use PyQt5 to write a concise (about 100‑line) desktop tool for quickly viewing COVID‑19 information.

Preparation

Install the required libraries with pip:

pip install PyQt5

pip install PyQtWebEngine

PyQt5 is a cross‑platform GUI toolkit that combines Python with the powerful Qt library, while PyQtWebEngine allows embedding web content directly into a Qt application.

Preview

When the application starts, the main window automatically loads the latest pandemic data using Baidu as the default search engine. Users can switch the engine (e.g., Baidu, Sina, NetEase, Tencent, Sogou, etc.) via a combo box in the interface.

Main Code (main_window.py)

<code># -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setContentsMargins(-1, 10, -1, 10)
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        self.comboBox = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox.setEnabled(False)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.horizontalLayout.addWidget(self.comboBox)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem1)
        self.verticalLayout_2.addLayout(self.horizontalLayout)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.horizontalLayout_2.addWidget(self.frame)
        self.verticalLayout_2.addLayout(self.horizontalLayout_2)
        self.verticalLayout_2.setStretch(0, 1)
        self.verticalLayout_2.setStretch(1, 20)
        self.verticalLayout_3.addLayout(self.verticalLayout_2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusBar = QtWidgets.QStatusBar(MainWindow)
        self.statusBar.setObjectName("statusBar")
        MainWindow.setStatusBar(self.statusBar)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "疫情情况快速查询"))
        self.label.setText(_translate("MainWindow", "引擎选择:"))
        self.comboBox.setItemText(0, _translate("MainWindow", "百度"))
        self.comboBox.setItemText(1, _translate("MainWindow", "新浪"))
        self.comboBox.setItemText(2, _translate("MainWindow", "网易"))
        self.comboBox.setItemText(3, _translate("MainWindow", "腾讯"))
        self.comboBox.setItemText(4, _translate("MainWindow", "搜狗"))
        self.comboBox.setItemText(5, _translate("MainWindow", "凤凰"))
        self.comboBox.setItemText(6, _translate("MainWindow", "猕尔"))
        self.comboBox.setItemText(7, _translate("MainWindow", "360"))
        self.comboBox.setItemText(8, _translate("MainWindow", "丁香园"))
        self.comboBox.setItemText(9, _translate("MainWindow", "华尔街"))
        self.comboBox.setItemText(10, _translate("MainWindow", "今日头条"))
        self.comboBox.setItemText(11, _translate("MainWindow", "美国中文网"))
</code>

Conclusion

The resulting PyQt5 application provides a compact, browser‑like interface for viewing pandemic data from several predefined sources, demonstrating how a small amount of Python code can deliver a functional desktop GUI.

Additional Resources

The article also includes a QR code linking to a free Python public‑course collection, but the core educational content is the step‑by‑step guide and the complete source code.

GUITutorialDesktop ApplicationCOVID-19PyQt5
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.