-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
69 lines (54 loc) · 2.5 KB
/
app.py
File metadata and controls
69 lines (54 loc) · 2.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import tkinter as tk
from tkinter import ttk
import psutil
class MemoryCleaner:
def __init__(self):
self.root = tk.Tk()
self.root.title('Memory Cleaner')
# Create a frame for the CPU usage gauge
self.cpu_frame = tk.Frame(self.root)
self.cpu_frame.pack()
# Label to display CPU usage
self.cpu_label = tk.Label(self.cpu_frame, text='CPU Usage: 0%', font=('Helvetica', '16'))
self.cpu_label.pack(side=tk.LEFT)
# Create a gauge for the CPU usage (using ttk.Progressbar)
self.cpu_gauge = ttk.Progressbar(self.cpu_frame, orient='horizontal', length=200, mode='determinate')
self.cpu_gauge.pack(side=tk.LEFT)
# Create a frame for the RAM usage gauge
self.ram_frame = tk.Frame(self.root)
self.ram_frame.pack()
# Label to display RAM usage
self.ram_label = tk.Label(self.ram_frame, text='RAM Usage: 0%', font=('Helvetica', '16'))
self.ram_label.pack(side=tk.LEFT)
# Create a gauge for the RAM usage (using ttk.Progressbar)
self.ram_gauge = ttk.Progressbar(self.ram_frame, orient='horizontal', length=200, mode='determinate')
self.ram_gauge.pack(side=tk.LEFT)
# Button to clear cache
self.clean_cache_button = tk.Button(self.root, text='Clean Cache', command=self.clear_cache)
self.clean_cache_button.pack()
# Update the gauges with initial values
self.update_gauges()
def update_gauges(self):
# Get CPU usage
cpu_usage = (psutil.cpu_percent() / psutil.cpu_count()) * 100
self.cpu_label.config(text=f'CPU Usage: {cpu_usage:.2f}%')
self.cpu_gauge['value'] = int(cpu_usage)
# Get RAM usage
mem_usage = psutil.virtual_memory().percent
self.ram_label.config(text=f'RAM Usage: {mem_usage}%')
self.ram_gauge['value'] = int(mem_usage)
# Update the gauges after a short delay to get updated values
self.root.after(1000, self.update_gauges)
def clear_cache(self):
try:
print("Closing unnecessary applications...")
app_names = ['chrome.exe', 'edge.exe', 'explorer.exe']
for app in app_names:
print(f"Closing {app} process")
except Exception as e:
print(f'Error closing application: {e}')
def run(self):
self.root.mainloop()
if __name__ == '__main__':
memory_cleaner = MemoryCleaner()
memory_cleaner.run()