Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071234567891011121314151617181920212223242526272829303132333435363738394041424344import 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()import streamlit as stimport pandas as pd
# Load data from a CSV filecsv_file = 'Bengaluru_House_Data.csv' # Replace with your CSV file pathdf = pd.read_csv(csv_file)
# Set the title of the web appst.title("CSV Data Table and Select Boxes Example")
# Define the options for the select boxesoptions1 = ["Low", "Medium", "High"]options2 = ["Option A", "Option B", "Option C"]options3 = ["Choice X", "Choice Y", "Choice Z"]
# Create the select boxesgrowth = st.selectbox("Growth", options1, index=0)income = st.selectbox("Income", options2, index=0)budget = st.selectbox("Budget", options3, index=0)
# Function to handle selection changesst.write(f"Selected Growth: {growth}")st.write(f"Selected Income: {income}")st.write(f"Selected Budget: {budget}")
# Display the dataframe as a tablest.dataframe(df)
# Optionally, you can add some stylingst.markdown("""<style> .stDataFrame { border: 2px solid black; } .stDataFrame thead th { background-color: lightblue; font-weight: bold; color: black; } .stDataFrame tbody td { border: 1px solid black; }</style>""", unsafe_allow_html=True)app.py+44-107