Monitor All System Information with Python-based Desktop App using PYQT or PYSIDE2/6 and PSUTIL – Featuring Modern GUI/ UI

Posted by


In this tutorial, we will walk through the process of designing and creating a desktop application to monitor all system information using Python, specifically with PyQt and Psutil libraries.

Step 1: Install the necessary libraries

Before we can start building our desktop application, we need to install the required libraries. Use the following commands to install the necessary libraries:

pip install pyqt5
pip install psutil

Step 2: Design the user interface

Now that we have installed the required libraries, we can start building our desktop application. We will use PyQt to design the user interface. Create a new Python file and add the following code:

from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
import psutil

class SystemMonitor(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("System Monitor")
        self.setGeometry(100, 100, 400, 400)

        layout = QVBoxLayout()

        self.cpu_label = QLabel()
        layout.addWidget(self.cpu_label)

        self.memory_label = QLabel()
        layout.addWidget(self.memory_label)

        self.disk_label = QLabel()
        layout.addWidget(self.disk_label)

        self.network_label = QLabel()
        layout.addWidget(self.network_label)

        self.setLayout(layout)

    def update_info(self):
        cpu_usage = psutil.cpu_percent()
        memory_usage = psutil.virtual_memory().percent
        disk_usage = psutil.disk_usage('/').percent
        network_usage = psutil.net_io_counters().bytes_sent / 1024

        self.cpu_label.setText(f"CPU Usage: {cpu_usage}%")
        self.memory_label.setText(f"Memory Usage: {memory_usage}%")
        self.disk_label.setText(f"Disk Usage: {disk_usage}%")
        self.network_label.setText(f"Network Usage: {network_usage} KB/s")

if __name__ == '__main__':
    app = QApplication([])
    system_monitor = SystemMonitor()
    system_monitor.show()

    timer = QTimer()
    timer.timeout.connect(system_monitor.update_info)
    timer.start(1000)

    app.exec_()

In this code, we create a SystemMonitor class that extends QWidget. We define the layout of the application using a QVBoxLayout and add labels to display the CPU usage, memory usage, disk usage, and network usage.

We also create a update_info method to fetch the system information using the psutil library and update the labels with the latest information.

Step 3: Running the application

To run the application, simply execute the Python file that contains the code mentioned above. You should see a window pop up displaying real-time system information.

You can further customize the UI by adding more widgets, styling the UI using CSS, or adding more functionality to the application.

That’s it! You have now created a desktop application to monitor all system information using Python, PyQt, and Psutil libraries. You can explore more features and functionalities offered by these libraries to enhance the application further.