Luminous Data Weaver 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 io
from PIL import Image, ImageTk
import numpy as np
class DataWeaverApp:
def __init__(self, root):
self.root = root
self.root.title("Luminous Data Weaver")
self.root.geometry("800x600")
self.notebook = ttk.Notebook(root)
self.notebook.pack(expand=True, fill="both", padx=10, pady=10)
self.create_data_tab()
self.create_visualization_tab()
self.create_transformation_tab()
self.create_about_tab()
self.df = None # Store loaded DataFrame
def create_data_tab(self):
data_tab = ttk.Frame(self.notebook)
self.notebook.add(data_tab, text="Data Input")
# File loading
load_frame = ttk.Frame(data_tab)
load_frame.pack(pady=10)
load_button = ttk.Button(load_frame, text="Load CSV/Excel", command=self.load_data)
load_button.pack(side="left", padx=5)
self.data_preview = tk.Text(data_tab, height=15, width=80, wrap=tk.WORD)
self.data_preview.pack(padx=10, pady=5)
self.data_preview.config(state=tk.DISABLED) # Read-only
def create_visualization_tab(self):
vis_tab = ttk.Frame(self.notebook)
self.notebook.add(vis_tab, text="Visualization")
self.vis_type_var = tk.StringVar(value="scatter") # Default
vis_type_frame = ttk.Frame(vis_tab)
vis_type_frame.pack(pady=5)
ttk.Radiobutton(vis_type_frame, text="Scatter", variable=self.vis_type_var, value="scatter").pack(side="left", padx=5)
ttk.Radiobutton(vis_type_frame, text="Bar", variable=self.vis_type_var, value="bar").pack(side="left", padx=5)
ttk.Radiobutton(vis_type_frame, text="Line", variable=self.vis_type_var, value="line").pack(side="left", padx=5)
self.x_col_var = tk.StringVar()
self.y_col_var = tk.StringVar()
col_select_frame = ttk.Frame(vis_tab)
col_select_frame.pack(pady=5)
ttk.Label(col_select_frame, text="X Column:").pack(side="left", padx=5)
self.x_col_dropdown = ttk.Combobox(col_select_frame, textvariable=self.x_col_var)
self.x_col_dropdown.pack(side="left", padx=5)
ttk.Label(col_select_frame, text="Y Column:").pack(side="left", padx=5)
self.y_col_dropdown = ttk.Combobox(col_select_frame, textvariable=self.y_col_var)
self.y_col_dropdown.pack(side="left", padx=5)
plot_button = ttk.Button(vis_tab, text="Generate Plot", command=self.generate_plot)
plot_button.pack(pady=5)
self.plot_frame = ttk.Frame(vis_tab)
self.plot_frame.pack(expand=True, fill="both", padx=10, pady=5)
def create_transformation_tab(self):
transform_tab = ttk.Frame(self.notebook)
self.notebook.add(transform_tab, text="Data Transformation")
transform_label = ttk.Label(transform_tab, text="Coming soon... (Placeholder for data cleaning/manipulation)")
transform_label.pack(pady=20)
def create_about_tab(self):
about_tab = ttk.Frame(self.notebook)
self.notebook.add(about_tab, text="About")
about_text = tk.Text(about_tab, height=10, width=70, wrap=tk.WORD)
about_text.pack(padx=10, pady=10)
about_text.insert(tk.END, "Luminous Data Weaver: A versatile tool for data exploration and visualization. This application provides a user-friendly interface to load, preview, visualize, and eventually transform tabular data. It supports CSV and Excel files. Future updates will include data cleaning, advanced visualizations, and more transformation options.")
about_text.config(state=tk.DISABLED)
def load_data(self):
file_path = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv"), ("Excel files", "*.xlsx;*.xls")])
if file_path:
try:
if file_path.endswith(".csv"):
self.df = pd.read_csv(file_path)
else:
self.df = pd.read_excel(file_path)
# Update preview
self.data_preview.config(state=tk.NORMAL)
self.data_preview.delete("1.0", tk.END)
self.data_preview.insert(tk.END, self.df.head(10).to_string() + "\n...") # Show only first 10 rows
self.data_preview.config(state=tk.DISABLED)
# Update column selection dropdowns
columns = list(self.df.columns)
self.x_col_dropdown['values'] = columns
self.y_col_dropdown['values'] = columns
except Exception as e:
messagebox.showerror("Error", f"Error loading data: {e}")
def generate_plot(self):
if self.df is None:
messagebox.showerror("Error", "No data loaded.")
return
x_col = self.x_col_var.get()
y_col = self.y_col_var.get()
vis_type = self.vis_type_var.get()
if not x_col or not y_col:
messagebox.showerror("Error", "Please select X and Y columns.")
return
try:
plt.clf()
if vis_type == "scatter":
plt.scatter(self.df[x_col], self.df[y_col])
elif vis_type == "bar":
plt.bar(self.df[x_col], self.df[y_col]) # Ensure both columns are suitable for bar chart
elif vis_type == "line":
plt.plot(self.df[x_col], self.df[y_col])
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.title(f"{vis_type.capitalize()} Plot of {y_col} vs {x_col}")
plt.grid(True)
# Embed plot in Tkinter window
fig = plt.gcf()
canvas = FigureCanvasTkAgg(fig, master=self.plot_frame)
canvas.draw()
canvas.get_tk_widget().pack(expand=True, fill="both")
except KeyError:
messagebox.showerror("Error", "Invalid column selection.")
except Exception as e:
messagebox.showerror("Error", f"Error generating plot: {e}")
if __name__ == "__main__":
root = tk.Tk()
app = DataWeaverApp(root)
root.mainloop()
👁️ Viewed: 7
Comments