Zenith Analyzer Python GUI

👤 Sharing: AI
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import seaborn as sns

class ZenithAnalyzer:
    def __init__(self, master):
        self.master = master
        master.title("Zenith Analyzer")

        # --- Data Storage --- #
        self.data = None

        # --- Style Configuration --- #
        self.style = ttk.Style()
        self.style.configure('TButton', padding=5, relief="raised")
        self.style.configure('TLabel', padding=5)

        # --- Main Frames --- #
        self.input_frame = ttk.Frame(master, padding=10)
        self.input_frame.pack(pady=10)

        self.output_frame = ttk.Frame(master, padding=10)
        self.output_frame.pack(pady=10)

        # --- Input Controls --- #
        self.load_button = ttk.Button(self.input_frame, text="Load Data (CSV, Excel)", command=self.load_data)
        self.load_button.pack(side=tk.LEFT, padx=5)

        self.analyze_button = ttk.Button(self.input_frame, text="Analyze Data", command=self.analyze_data, state=tk.DISABLED)
        self.analyze_button.pack(side=tk.LEFT, padx=5)

        self.clear_button = ttk.Button(self.input_frame, text="Clear", command=self.clear_results, state=tk.DISABLED)
        self.clear_button.pack(side=tk.LEFT, padx=5)

        # --- Output Area (Initially Empty) --- #
        self.notebook = ttk.Notebook(self.output_frame)
        self.notebook.pack(expand=True, fill=tk.BOTH)

        self.details_button = ttk.Button(self.output_frame, text="Details", command=self.show_details)
        self.details_button.pack(side=tk.BOTTOM, pady=5)


    def load_data(self):
        filepath = filedialog.askopenfilename(filetypes=[("CSV Files", "*.csv"), ("Excel Files", "*.xlsx;*.xls")])
        if filepath:
            try:
                if filepath.endswith('.csv'):
                    self.data = pd.read_csv(filepath)
                else:
                    self.data = pd.read_excel(filepath)
                messagebox.showinfo("Data Loaded", "Data loaded successfully.")
                self.analyze_button['state'] = tk.NORMAL  # Enable analyze button
                self.clear_button['state'] = tk.NORMAL
            except Exception as e:
                messagebox.showerror("Error", f"Error loading data: {e}")

    def analyze_data(self):
        if self.data is None:
            messagebox.showerror("Error", "No data loaded.")
            return

        # --- Basic Descriptive Statistics --- #
        stats_tab = ttk.Frame(self.notebook)
        self.notebook.add(stats_tab, text="Statistics")
        stats_text = tk.Text(stats_tab, wrap=tk.WORD)
        stats_text.pack(expand=True, fill=tk.BOTH, padx=5, pady=5)
        stats_text.insert(tk.END, self.data.describe().to_string())
        stats_text['state'] = tk.DISABLED # Make it read-only

        # --- Simple Visualization (Scatter Plot) --- #
        try:
            vis_tab = ttk.Frame(self.notebook)
            self.notebook.add(vis_tab, text="Visualization")

            # Choose two columns for scatter plot
            columns = self.data.columns.tolist()
            if len(columns) < 2:
                messagebox.showerror("Error", "Not enough columns for a scatter plot.")
                return

            x_col = columns[0]
            y_col = columns[1]

            fig, ax = plt.subplots(figsize=(6, 4))
            sns.scatterplot(x=x_col, y=y_col, data=self.data, ax=ax)
            ax.set_title(f'{x_col} vs. {y_col}')
            ax.set_xlabel(x_col)
            ax.set_ylabel(y_col)
            fig.tight_layout()

            canvas = FigureCanvasTkAgg(fig, master=vis_tab)
            canvas.draw()
            canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        except Exception as e:
            messagebox.showerror("Error", f"Error creating visualization: {e}")

    def clear_results(self):
        for tab_id in self.notebook.tabs():
            self.notebook.forget(tab_id)

    def show_details(self):
        messagebox.showinfo("Zenith Analyzer Details",
                            "Zenith Analyzer is a versatile tool for quickly loading, exploring, and visualizing data. It supports CSV and Excel file formats.  It provides basic descriptive statistics and a scatter plot visualization.  More advanced features can be implemented based on user needs.")


root = tk.Tk()
app = ZenithAnalyzer(root)
root.mainloop()
👁️ Viewed: 5

Comments