Harshitn24 commited on
Commit
511b495
1 Parent(s): d5e6e49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -107
app.py CHANGED
@@ -1,107 +1,44 @@
1
- import tkinter as tk
2
- from tkinter import ttk
3
- import pandas as pd
4
-
5
- # Create the main application window
6
- root = tk.Tk()
7
- root.title("Select Box Example")
8
- root.geometry("300x250")
9
-
10
- # Define the options for the select boxes
11
- options1 = ["Low", "Medium", "High"]
12
- options2 = ["Option A", "Option B", "Option C"]
13
- options3 = ["Choice X", "Choice Y", "Choice Z"]
14
-
15
- # Function to handle selection changes
16
- def on_select(event):
17
- print("Selected:", combo1.get(), combo2.get(), combo3.get())
18
-
19
- # Create and place the first label and select box
20
- label1 = tk.Label(root, text="Growth")
21
- label1.pack(pady=(10, 0)) # Add padding at the top
22
- combo1 = ttk.Combobox(root, values=options1)
23
- combo1.set("Select an option") # Set default text
24
- combo1.pack(pady=(0, 10)) # Add padding at the bottom
25
-
26
- # Create and place the second label and select box
27
- label2 = tk.Label(root, text="Income")
28
- label2.pack(pady=(10, 0)) # Add padding at the top
29
- combo2 = ttk.Combobox(root, values=options2)
30
- combo2.set("Select an option") # Set default text
31
- combo2.pack(pady=(0, 10)) # Add padding at the bottom
32
-
33
- # Create and place the third label and select box
34
- label3 = tk.Label(root, text="Budget")
35
- label3.pack(pady=(10, 0)) # Add padding at the top
36
- combo3 = ttk.Combobox(root, values=options3)
37
- combo3.set("Select an option") # Set default text
38
- combo3.pack(pady=(0, 10)) # Add padding at the bottom
39
-
40
- # Bind the select boxes to the on_select function
41
- combo1.bind("<<ComboboxSelected>>", on_select)
42
- combo2.bind("<<ComboboxSelected>>", on_select)
43
- combo3.bind("<<ComboboxSelected>>", on_select)
44
-
45
- # # Start the main event loop
46
- # root.mainloop()
47
-
48
-
49
- # import tkinter as tk
50
- # from tkinter import ttk
51
- # import pandas as pd
52
-
53
- # Load data from a CSV file
54
- csv_file = 'Bengaluru_House_Data.csv' # Replace with your CSV file path
55
- df = pd.read_csv(csv_file)
56
-
57
- # Create the main application window
58
- # root = tk.Tk()
59
- # root.title("CSV Data Table")
60
-
61
- style = ttk.Style()
62
- style.configure("Treeview",
63
- background="white",
64
- foreground="black",
65
- fieldbackground="white",
66
- bordercolor="black",
67
- borderwidth=2)
68
- style.configure("Treeview.Heading",
69
- background="lightblue",
70
- foreground="black",
71
- font=('Arial', 10, 'bold'))
72
-
73
- style.map('Treeview',
74
- background=[('selected', 'blue')],
75
- foreground=[('selected', 'white')])
76
- style.layout("Treeview", [('Treeview.treearea', {'sticky': 'nswe'})])
77
- # Create a frame for the table
78
- frame = ttk.Frame(root)
79
- frame.pack(fill=tk.BOTH, expand=True)
80
-
81
- # Create a Treeview widget
82
- tree = ttk.Treeview(frame, columns=list(df.columns), show='headings')
83
-
84
- # Define the column headings
85
- for col in df.columns:
86
- tree.heading(col, text=col)
87
- tree.column(col, anchor=tk.CENTER, width=100)
88
-
89
- # Add the data to the table
90
- for index, row in df.iterrows():
91
- tree.insert("", tk.END, values=list(row))
92
-
93
- # Add a vertical scrollbar
94
- vsb = ttk.Scrollbar(frame, orient="vertical", command=tree.yview)
95
- tree.configure(yscrollcommand=vsb.set)
96
- vsb.pack(side='right', fill='y')
97
-
98
- # Add a horizontal scrollbar
99
- hsb = ttk.Scrollbar(frame, orient="horizontal", command=tree.xview)
100
- tree.configure(xscrollcommand=hsb.set)
101
- hsb.pack(side='bottom', fill='x')
102
-
103
- # Pack the Treeview widget
104
- tree.pack(fill=tk.BOTH, expand=True)
105
-
106
- # Start the main event loop
107
- root.mainloop()
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ # Load data from a CSV file
5
+ csv_file = 'Bengaluru_House_Data.csv' # Replace with your CSV file path
6
+ df = pd.read_csv(csv_file)
7
+
8
+ # Set the title of the web app
9
+ st.title("CSV Data Table and Select Boxes Example")
10
+
11
+ # Define the options for the select boxes
12
+ options1 = ["Low", "Medium", "High"]
13
+ options2 = ["Option A", "Option B", "Option C"]
14
+ options3 = ["Choice X", "Choice Y", "Choice Z"]
15
+
16
+ # Create the select boxes
17
+ growth = st.selectbox("Growth", options1, index=0)
18
+ income = st.selectbox("Income", options2, index=0)
19
+ budget = st.selectbox("Budget", options3, index=0)
20
+
21
+ # Function to handle selection changes
22
+ st.write(f"Selected Growth: {growth}")
23
+ st.write(f"Selected Income: {income}")
24
+ st.write(f"Selected Budget: {budget}")
25
+
26
+ # Display the dataframe as a table
27
+ st.dataframe(df)
28
+
29
+ # Optionally, you can add some styling
30
+ st.markdown("""
31
+ <style>
32
+ .stDataFrame {
33
+ border: 2px solid black;
34
+ }
35
+ .stDataFrame thead th {
36
+ background-color: lightblue;
37
+ font-weight: bold;
38
+ color: black;
39
+ }
40
+ .stDataFrame tbody td {
41
+ border: 1px solid black;
42
+ }
43
+ </style>
44
+ """, unsafe_allow_html=True)