-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_manager -GUI-PyQt.py
More file actions
41 lines (29 loc) · 966 Bytes
/
task_manager -GUI-PyQt.py
File metadata and controls
41 lines (29 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import psutil
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QTimer
class TaskManager(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Python Task Manager (PyQt)")
self.setGeometry(200, 200, 300, 150)
self.label = QLabel("Loading...", self)
layout = QVBoxLayout()
layout.addWidget(self.label)
self.setLayout(layout)
self.timer = QTimer()
self.timer.timeout.connect(self.update_stats)
self.timer.start(1000)
def update_stats(self):
cpu = psutil.cpu_percent()
mem = psutil.virtual_memory()
self.label.setText(
f"CPU Usage : {cpu}%\n"
f"Memory : {mem.percent}%"
)
def main():
app = QApplication(sys.argv)
win = TaskManager()
win.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()