premier test
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
45
cpu_monitor.py
Normal file
45
cpu_monitor.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# CPU Monitor - Run with python cpu_monitor_gui.py
|
||||
# Requirements: psutil (>=5.8.0), tkinter
|
||||
# Install: pip install psutil tkinter
|
||||
|
||||
import tkinter as tk
|
||||
import psutil
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
# Main window setup
|
||||
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
|
||||
progress_bar = tk.Progressbar(root, orient="horizontal", maximum=100, mode="indeterminate")
|
||||
progress_bar.pack(pady=10)
|
||||
|
||||
# Time label
|
||||
time_label = tk.Label(root, text="Time: 00:00:00", font=("Arial", 14))
|
||||
time_label.pack(pady=10)
|
||||
|
||||
# Quit button
|
||||
quit_button = tk.Button(root, text="Quit", command=root.destroy)
|
||||
quit_button.pack(pady=10)
|
||||
|
||||
# Update GUI every 2 seconds
|
||||
def update_gui():
|
||||
while True:
|
||||
cpu_percent = psutil.cpu_percent()
|
||||
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)
|
||||
|
||||
# Start the update loop
|
||||
update_gui()
|
||||
|
||||
# Run the Tkinter main loop
|
||||
root.mainloop()
|
||||
Reference in New Issue
Block a user