-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeViewData.py
44 lines (35 loc) · 1.26 KB
/
TreeViewData.py
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
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
import csv
def open_csv_file():
file_path = "Patient_Details.csv"
if file_path:
display_csv_data(file_path)
def display_csv_data(file_path):
try:
with open(file_path, 'r', newline='') as file:
csv_reader = csv.reader(file)
header = next(csv_reader) # Read the header row
tree.delete(*tree.get_children()) # Clear the current data
tree["columns"] = header
for col in header:
tree.heading(col, text=col)
tree.column(col, width=100)
for row in csv_reader:
tree.insert("", "end", values=row)
#status_label.config(text=f"CSV file loaded: {file_path}")
except Exception as e:
status_label.config(text=f"Error: {str(e)}")
root = tk.Tk()
root.title("View Patients Data")
"""
open_button = tk.Button(root, text="Open CSV File", command=open_csv_file)
open_button.pack(padx=20, pady=10)
"""
tree = ttk.Treeview(root, show="headings")
tree.pack(padx=20, pady=20, fill="both", expand=True)
status_label = tk.Label(root, text="", padx=20, pady=10)
status_label.pack()
open_csv_file()
root.mainloop()