Spaces:
Sleeping
Sleeping
File size: 3,450 Bytes
98fb261 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
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()
|