replace tkinter GUI with simple CLI monitor
This commit is contained in:
@@ -1,45 +1,29 @@
|
|||||||
# CPU Monitor - Run with python cpu_monitor_gui.py
|
#!/usr/bin/env python3
|
||||||
# Requirements: psutil (>=5.8.0), tkinter
|
# Lancement: python cpu_monitor.py
|
||||||
# Install: pip install psutil tkinter
|
|
||||||
|
|
||||||
import tkinter as tk
|
|
||||||
import psutil
|
|
||||||
import time
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
# Main window setup
|
import psutil
|
||||||
root = tk.Tk()
|
|
||||||
root.title("CPU Monitor")
|
|
||||||
root.geometry("400x200")
|
|
||||||
|
|
||||||
# CPU usage label
|
|
||||||
cpu_label = tk.Label(root, text="CPU Usage: 0%", font=("Arial", 16))
|
|
||||||
cpu_label.pack(pady=10)
|
|
||||||
|
|
||||||
# Progress bar for CPU usage
|
def format_line() -> str:
|
||||||
progress_bar = tk.Progressbar(root, orient="horizontal", maximum=100, mode="indeterminate")
|
now = datetime.now().strftime("%H:%M:%S")
|
||||||
progress_bar.pack(pady=10)
|
cpu = psutil.cpu_percent(interval=None)
|
||||||
|
ram = psutil.virtual_memory().percent
|
||||||
|
return f"{now} | CPU: {cpu:5.1f}% | RAM: {ram:5.1f}%"
|
||||||
|
|
||||||
# Time label
|
|
||||||
time_label = tk.Label(root, text="Time: 00:00:00", font=("Arial", 14))
|
|
||||||
time_label.pack(pady=10)
|
|
||||||
|
|
||||||
# Quit button
|
def main() -> None:
|
||||||
quit_button = tk.Button(root, text="Quit", command=root.destroy)
|
print("Monitoring CPU/RAM. Ctrl+C pour arrêter.")
|
||||||
quit_button.pack(pady=10)
|
try:
|
||||||
|
|
||||||
# Update GUI every 2 seconds
|
|
||||||
def update_gui():
|
|
||||||
while True:
|
while True:
|
||||||
cpu_percent = psutil.cpu_percent()
|
print(format_line())
|
||||||
current_time = datetime.now().strftime("%H:%M:%S")
|
|
||||||
cpu_label.config(text=f"CPU Usage: {cpu_percent}%")
|
|
||||||
progress_bar.config(value=cpu_percent)
|
|
||||||
time_label.config(text=current_time)
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nArrêt propre.")
|
||||||
|
|
||||||
# Start the update loop
|
|
||||||
update_gui()
|
|
||||||
|
|
||||||
# Run the Tkinter main loop
|
if __name__ == "__main__":
|
||||||
root.mainloop()
|
main()
|
||||||
|
|
||||||
|
|||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
psutil
|
||||||
Reference in New Issue
Block a user