-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditableTable.py
More file actions
36 lines (30 loc) · 1.42 KB
/
EditableTable.py
File metadata and controls
36 lines (30 loc) · 1.42 KB
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
from Table import *
from Biblio import *
class EditableTable(ttk.Frame):
def __init__(self, parent):
ttk.Frame.__init__(self, parent)
self.parent = parent
self.message_label = ttk.Label(self, text="No data imported yet.", font=('Helvetica', 12), foreground='black')
self.message_label.pack(expand=True)
self.df = pd.DataFrame()
self.pt = Table(self, showstatusbar= True, width=800, height = 400)
self.pt.pack(expand=True, fill="both")
def create_data(self, data):
for widget in self.winfo_children():
widget.destroy()
self.df = pd.DataFrame(data)
self.pt = Table(self, dataframe=self.df, showtoolbar=False, showstatusbar=True, width=800, height=400)
self.pt.show()
def import_data(self):
file_path = filedialog.askopenfilename(title="Choose a file", filetypes=[("CSV files", "*.csv"), ("All files", "*.*")])
if file_path:
try:
new_data = pd.read_csv(file_path)
self.create_data(new_data)
messagebox.showinfo("Success", "Data imported successfully.")
except Exception as e:
messagebox.showerror("Error", f"Error during data import:\n{str(e)}")
print(str(e))
def show_table(self):
self.pack(side=tk.LEFT, expand=True, fill="both", padx=10, pady=10)
self.pt.show()