Spaces:
Sleeping
Sleeping
| import tkinter as tk | |
| from tkinter import ttk | |
| import pandas as pd | |
| # Create the main application window | |
| root = tk.Tk() | |
| root.title("Select Box Example") | |
| root.geometry("300x250") | |
| # Define the options for the select boxes | |
| options1 = ["Low", "Medium", "High"] | |
| options2 = ["Option A", "Option B", "Option C"] | |
| options3 = ["Choice X", "Choice Y", "Choice Z"] | |
| # Function to handle selection changes | |
| def on_select(event): | |
| print("Selected:", combo1.get(), combo2.get(), combo3.get()) | |
| # Create and place the first label and select box | |
| label1 = tk.Label(root, text="Growth") | |
| label1.pack(pady=(10, 0)) # Add padding at the top | |
| combo1 = ttk.Combobox(root, values=options1) | |
| combo1.set("Select an option") # Set default text | |
| combo1.pack(pady=(0, 10)) # Add padding at the bottom | |
| # Create and place the second label and select box | |
| label2 = tk.Label(root, text="Income") | |
| label2.pack(pady=(10, 0)) # Add padding at the top | |
| combo2 = ttk.Combobox(root, values=options2) | |
| combo2.set("Select an option") # Set default text | |
| combo2.pack(pady=(0, 10)) # Add padding at the bottom | |
| # Create and place the third label and select box | |
| label3 = tk.Label(root, text="Budget") | |
| label3.pack(pady=(10, 0)) # Add padding at the top | |
| combo3 = ttk.Combobox(root, values=options3) | |
| combo3.set("Select an option") # Set default text | |
| combo3.pack(pady=(0, 10)) # Add padding at the bottom | |
| # Bind the select boxes to the on_select function | |
| combo1.bind("<<ComboboxSelected>>", on_select) | |
| combo2.bind("<<ComboboxSelected>>", on_select) | |
| combo3.bind("<<ComboboxSelected>>", on_select) | |
| # # Start the main event loop | |
| # root.mainloop() | |
| # import tkinter as tk | |
| # from tkinter import ttk | |
| # import pandas as pd | |
| # Load data from a CSV file | |
| csv_file = 'Bengaluru_House_Data.csv' # Replace with your CSV file path | |
| df = pd.read_csv(csv_file) | |
| # Create the main application window | |
| # root = tk.Tk() | |
| # root.title("CSV Data Table") | |
| style = ttk.Style() | |
| style.configure("Treeview", | |
| background="white", | |
| foreground="black", | |
| fieldbackground="white", | |
| bordercolor="black", | |
| borderwidth=2) | |
| style.configure("Treeview.Heading", | |
| background="lightblue", | |
| foreground="black", | |
| font=('Arial', 10, 'bold')) | |
| style.map('Treeview', | |
| background=[('selected', 'blue')], | |
| foreground=[('selected', 'white')]) | |
| style.layout("Treeview", [('Treeview.treearea', {'sticky': 'nswe'})]) | |
| # Create a frame for the table | |
| frame = ttk.Frame(root) | |
| frame.pack(fill=tk.BOTH, expand=True) | |
| # Create a Treeview widget | |
| tree = ttk.Treeview(frame, columns=list(df.columns), show='headings') | |
| # Define the column headings | |
| for col in df.columns: | |
| tree.heading(col, text=col) | |
| tree.column(col, anchor=tk.CENTER, width=100) | |
| # Add the data to the table | |
| for index, row in df.iterrows(): | |
| tree.insert("", tk.END, values=list(row)) | |
| # Add a vertical scrollbar | |
| vsb = ttk.Scrollbar(frame, orient="vertical", command=tree.yview) | |
| tree.configure(yscrollcommand=vsb.set) | |
| vsb.pack(side='right', fill='y') | |
| # Add a horizontal scrollbar | |
| hsb = ttk.Scrollbar(frame, orient="horizontal", command=tree.xview) | |
| tree.configure(xscrollcommand=hsb.set) | |
| hsb.pack(side='bottom', fill='x') | |
| # Pack the Treeview widget | |
| tree.pack(fill=tk.BOTH, expand=True) | |
| # Start the main event loop | |
| root.mainloop() | |