I'm wondering why the scrollbar of the treeview are not filling the x and y axis with the following code. The only appear in the middle of the axis
Any idea ?
Thanks
class DataTable(ttk.Treeview):
def __init__(self, parent):
super().__init__(parent)
scroll_Y = tk.Scrollbar(self, orient="vertical", command=self.yview)
scroll_X = tk.Scrollbar(self, orient="horizontal", command=self.xview)
self.configure(yscrollcommand=scroll_Y.set, xscrollcommand=scroll_X.set)
scroll_Y.pack(side="bottom", fill="y")
scroll_X.pack(side="right", fill="x")
self.stored_dataframe = pd.DataFrame()
self.bind("<Double-1>", lambda event: self.onDoubleClick(event))
def set_datatable(self, dataframe: pd.DataFrame):
self.delete(*self.get_children())
columns = list(dataframe.columns)
self.__setitem__("column", columns)
self.__setitem__("show", "headings")
for col in columns:
self.heading(col, text=col)
df_rows = dataframe.to_numpy().tolist()
for row in df_rows:
self.insert("", "end", values=row)
return None
class ContentPage(tk.Frame):
def __init__(self, parent):
super().__init__(parent)
#TreeView
self.data_table = DataTable(parent)
self.data_table.place(relx=0, rely=0, relheight=0.90, relwidth=1)
# some process to create a pandas dataframe
self.data_table.set_datatable(dataframe=df)
You have put the scrollbars in wrong sides.
Correct packing:
scroll_Y.pack(side="right", fill="y") # vertical one at the right side
scroll_X.pack(side="bottom", fill="x") # horizontal one at the bottom side