In this tutorial, I will show you how to create a desktop application using Python, PyQt, and Psutil to monitor all system information in a modern GUI/UI. Psutil is a convenient cross-platform library for retrieving system information such as CPU, memory, disk, and network usage, while PyQt is a robust toolkit for crafting graphical user interfaces.
Let’s get started by setting up our development environment and installing the necessary libraries. Make sure you have Python installed on your system before proceeding.
Step 1: Install PyQt and Psutil
Open your command prompt or terminal and run the following commands to install PyQt5, PySide2 or PySide6, Psutil:
pip install PyQt5
pip install pyqt5-tools
pip install psutil
pip install PySide2
pip install PySide6
Step 2: Designing the GUI
We will use Qt Designer, which is part of the PyQt package, to design our GUI. Open Qt Designer by running the following command in your terminal:
designer
Design your UI by dragging and dropping widgets from the toolbox. You can create labels, buttons, and other widgets to display system information. Save your UI file as monitor.ui
.
Step 3: Convert UI file to Python code
We will convert our UI file to Python code using the pyuic5
or pyuic6
command-line tool, depending on the PyQt version you are using.
pyuic5 monitor.ui -o monitor_ui.py
or
pyuic6 monitor.ui -o monitor_ui.py
This command will generate a Python file monitor_ui.py
containing the code for your GUI.
Step 4: Create the main application
Now, let’s create the main Python application that will fetch system information using Psutil and display it in the GUI. Create a new Python file main.py
and add the following code:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from monitor_ui import Ui_MainWindow
import psutil
class MonitorApp(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.update_info()
def update_info(self):
cpu_percent = psutil.cpu_percent()
memory = psutil.virtual_memory()
disk = psutil.disk_usage('/')
network = psutil.net_io_counters()
self.label_cpu.setText(f'CPU: {cpu_percent}%')
self.label_memory.setText(f'Memory: {memory.percent}%')
self.label_disk.setText(f'Disk: {disk.percent}%')
self.label_network.setText(f'Bytes Sent: {network.bytes_sent}, Bytes Received: {network.bytes_recv}')
if __name__ == '__main__':
app = QApplication(sys.argv)
monitor = MonitorApp()
monitor.show()
sys.exit(app.exec_())
This code initializes the application, fetches system information using Psutil, and updates the UI labels with the data.
Step 5: Run the application
To run the application, simply execute the main.py
file:
python main.py
You should see the GUI window displaying real-time system information such as CPU usage, memory usage, disk usage, and network usage.
Congratulations! You have successfully created a desktop application to monitor all system information using Python, PyQt, and Psutil. Feel free to customize the GUI and add more features to enhance the monitoring capabilities of the application.
What is this qt designer. Please share the link
Guy do one course on udemy . You are the best . I thank you too much.