I am researching how to use Tkinter ( CustomTkinter ) and I would like to display a pandastable using the Tkinter GRID layout, instead of the PACK layout. The code below will show the table but it is taking up the entire frame.
The entire project is very large and complex but here is the relevant code:
import customtkinter as ctk
import pandas as pd
from tkinter import END
from pandastable import Table
class DisplayTable(ctk.CTkFrame):
def __init__(self, parent):
ctk.CTkFrame.__init__(self, parent)
label = ctk.CTkLabel(self, text="DisplayTable")
label.grid(row=0, column=1, padx=10, pady=10, columnspan=4)
df = pd.read_csv("data/data_points.csv")
self.table = Table(self, dataframe=df, showtoolbar=True, showstatusbar=True)
self.table.grid(row=1, column=1, padx=10, pady=10, columnspan=4)
self.table.show()
My question is how to apply the GRID layout to the pandastable so that I have a label at the top of the screen and panddastable below?
First of all, I think there might be some issue with bindings in CustomTkinter because I got the same error as here: AttributeError in Ctk For some reason, Ctk doesn't allow
bind_allThe solution should be to have the master of the Table as a separate frame. This worked great when I used regular Tkinter (without this extra frame, the Table took up the whole window also):
If I try the same thing with CustomTkinter I get the AttributeError I mentioned in the beginning.
Workaround with using CustomTkinter anyway (use at your own risk because it involves changing behaviors that the author of the code took into consideration):
Code with Ctk:
Now when you get this error:
Follow the link to the
bind_allmethod, comment out theraise AttributeErrorand just addpassThis got it to work but I have no idea why
bind_allcouldresult in undefined behaviorusing CustomTkinter so again, use at your own risk.