GRA Python GUI

👤 Sharing: AI
import tkinter as tk
from tkinter import ttk
import psutil
import platform
import datetime

class ResourceAnalyzer:
    def __init__(self, master):
        self.master = master
        master.title("Graphical Resource Analyzer (GRA)")
        master.geometry("600x400")
        master.resizable(False, False)

        self.style = ttk.Style()
        self.style.theme_use('clam')

        # CPU Usage
        self.cpu_frame = ttk.LabelFrame(master, text="CPU Usage", padding=10)
        self.cpu_frame.pack(fill=tk.X, padx=10, pady=10)
        self.cpu_label = ttk.Label(self.cpu_frame, text="CPU Usage: ")
        self.cpu_label.pack(side=tk.LEFT)
        self.cpu_value = tk.StringVar()
        self.cpu_value_label = ttk.Label(self.cpu_frame, textvariable=self.cpu_value)
        self.cpu_value_label.pack(side=tk.LEFT)

        # Memory Usage
        self.memory_frame = ttk.LabelFrame(master, text="Memory Usage", padding=10)
        self.memory_frame.pack(fill=tk.X, padx=10)
        self.memory_label = ttk.Label(self.memory_frame, text="Memory Usage: ")
        self.memory_label.pack(side=tk.LEFT)
        self.memory_value = tk.StringVar()
        self.memory_value_label = ttk.Label(self.memory_frame, textvariable=self.memory_value)
        self.memory_value_label.pack(side=tk.LEFT)

        # Disk Usage
        self.disk_frame = ttk.LabelFrame(master, text="Disk Usage", padding=10)
        self.disk_frame.pack(fill=tk.X, padx=10, pady=10)
        self.disk_label = ttk.Label(self.disk_frame, text="Disk Usage: ")
        self.disk_label.pack(side=tk.LEFT)
        self.disk_value = tk.StringVar()
        self.disk_value_label = ttk.Label(self.disk_frame, textvariable=self.disk_value)
        self.disk_value_label.pack(side=tk.LEFT)

        # Network Usage (Simple Bytes Sent/Received)
        self.network_frame = ttk.LabelFrame(master, text="Network Usage", padding=10)
        self.network_frame.pack(fill=tk.X, padx=10)
        self.network_label = ttk.Label(self.network_frame, text="Network: ")
        self.network_label.pack(side=tk.LEFT)
        self.network_value = tk.StringVar()
        self.network_value_label = ttk.Label(self.network_frame, textvariable=self.network_value)
        self.network_value_label.pack(side=tk.LEFT)

        # System Information
        self.sysinfo_frame = ttk.LabelFrame(master, text="System Information", padding=10)
        self.sysinfo_frame.pack(fill=tk.X, padx=10, pady=10)
        self.system_info = f"System: {platform.system()} | Node: {platform.node()} | Release: {platform.release()} | Version: {platform.version()} | Machine: {platform.machine()} | Processor: {platform.processor()}"
        self.sysinfo_label = ttk.Label(self.sysinfo_frame, text=self.system_info, wraplength=580)
        self.sysinfo_label.pack()

        # Last Updated
        self.last_updated_frame = ttk.LabelFrame(master, text="Last Updated", padding=10)
        self.last_updated_frame.pack(fill=tk.X, padx=10)
        self.last_updated_value = tk.StringVar()
        self.last_updated_label = ttk.Label(self.last_updated_frame, textvariable=self.last_updated_value)
        self.last_updated_label.pack(side=tk.LEFT)

        # About Button
        self.about_button = ttk.Button(master, text="About GRA", command=self.show_about)
        self.about_button.pack(pady=10)

        self.update_resource_info()

    def update_resource_info(self):
        cpu_percent = psutil.cpu_percent(interval=1)
        self.cpu_value.set(f"{cpu_percent}%")

        memory = psutil.virtual_memory()
        memory_percent = memory.percent
        self.memory_value.set(f"{memory_percent}%")

        disk = psutil.disk_usage('/')
        disk_percent = disk.percent
        self.disk_value.set(f"{disk_percent}%")

        net_io = psutil.net_io_counters()
        self.network_value.set(f"Sent: {net_io.bytes_sent} B | Received: {net_io.bytes_recv} B")

        now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.last_updated_value.set(now)

        self.master.after(1000, self.update_resource_info)

    def show_about(self):
        about_window = tk.Toplevel(self.master)
        about_window.title("About Graphical Resource Analyzer")
        about_window.geometry("400x300")

        about_text = """Graphical Resource Analyzer (GRA) is a real-time system monitoring tool designed to provide users with insights into their computer's resource usage.

It tracks CPU usage, memory consumption, disk activity, and network throughput. GRA provides a clear, concise overview of system performance.

Key Features:
- Real-time CPU, Memory, Disk, and Network Monitoring
- System Information Display
- User-friendly Graphical Interface

This application is designed to be lightweight and efficient, providing valuable information without impacting system performance.

Developed with Python and Tkinter."

        about_label = tk.Label(about_window, text=about_text, justify=tk.LEFT, padx=10, pady=10)
        about_label.pack()

root = tk.Tk()
app = ResourceAnalyzer(root)
root.mainloop()
👁️ Viewed: 8

Comments