I'm trying to display a CSV table in a frame inside a TAB in tabview, using customtkinter and pandastable as modules.
I don't know why but it's giving me this error:
AttributeError: 'bind_all' is not allowed, when using pandastable with tabview
It's not giving any errors when I try to do exact same thing inside the main window, or using an external window.
import customtkinter
from tkinter import filedialog as fd
from pandastable import Table, TableModel
import pandas as pd
import traceback
class MyTabView(customtkinter.CTkTabview):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)
self.master = master
self.toplevel_window = None
self.TAB1 = "Initial configuration"
self.TAB2 = "Progress status"
self.TAB3 = "Final result"
# create tabs
self.add(self.TAB1)
self.add(self.TAB2)
self.add(self.TAB3)
self.tab(self.TAB1).grid_columnconfigure((0,1),weight=1)
# add widgets on tabs
self.button_file_path = customtkinter.CTkButton(master=self.tab(self.TAB1), text="Select CSV file", command=self.get_file_path)
self.button_file_path.grid(row=0, column=0, padx=20, pady=10, sticky = "we")
self.select_column_label = customtkinter.CTkLabel(master = self.tab(self.TAB1), text="Select column from CSV")
self.select_column_label.grid(row=2, column=0, padx=20, pady=10, sticky = "we")
self.select_column_option = customtkinter.CTkOptionMenu(master = self.tab(self.TAB1), values=[])
self.select_column_option.grid(row=2, column=1, padx=20, pady=10, sticky = "we")
def showCSV(self):
self.csv_frame = customtkinter.CTkFrame(self.tab(self.TAB1))
self.csv_frame.grid(row = 1 , column = 0 , padx = 20, pady = 20, sticky = "nswe", columnspan = 2)
egypt_df = pd.read_csv(self.file_path, encoding='utf-8')
try:
self.table = pt = Table(parent=self.csv_frame, dataframe=egypt_df, showtoolbar=False, showstatusbar=False, editable=False)
pt.show()
except Exception as e:
print("Could not display CSV table:", e)
traceback.print_exc()
# if self.toplevel_window is None or not self.toplevel_window.winfo_exists():
# self.toplevel_window = CsvTableWindow(self.file_path) # create window if its None or destroyed
# else:
# self.toplevel_window.focus()
def get_file_path(self):
print("button1")
self.file_path = fd.askopenfilename()
try:
assert ((".csv") in self.file_path)
print(self.file_path)
egypt_df = pd.read_csv(self.file_path, encoding='utf-8')
print(egypt_df)
except AssertionError:
# Da cambiare con popup
print("This is not a CSV file!")
self.button_show_csv =customtkinter.CTkButton(master=self.tab(self.TAB1), text = "Show CSV table", command=self.showCSV)
self.button_show_csv.grid(row=0, column=1, padx=20, pady=10, sticky = "we")
class CsvTableWindow(customtkinter.CTkToplevel):
def __init__(self, path):
print(path)
super().__init__()
self.grid_columnconfigure(0, weight=0)
self.frame = customtkinter.CTkFrame(self)
self.frame.grid(row = 0, column = 0, padx = 20, pady =20, sticky = "nswe")
egypt_df = pd.read_csv(path, encoding='utf-8')
try:
self.table = pt = Table(parent=self, dataframe=egypt_df, showtoolbar=False, showstatusbar=False, editable=False)
pt.show()
except Exception as e:
print("Could not display CSV table:", e)
traceback.print_exc()
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
customtkinter.set_default_color_theme("dark-blue")
customtkinter.set_appearance_mode("dark")
self.geometry("800x600")
self.title("Similarity search engine")
self.tab_view = MyTabView(master=self)
self.grid_columnconfigure(0,weight=1)
self.grid_rowconfigure(0,weight=1)
self.tab_view.grid(row=0, column=0, padx=20, pady=20, sticky = "nswe")
app = App()
app.mainloop()
I tried different combinations of frames and windows, and it didn't change much