I love the ttkbootstrap project, but I've been pulling my hair out trying to figure out why this is happening:
Here's my Code:
import tkinter as tk
import ttkbootstrap as ttkb
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.constants import *
class MainAppWindow(ttkb.Window):
def __init__(self,root):
self.window = root
self.window.geometry('900x600')
#initialize table
self.coldata=[{"text":"Spam","stretch":True},
{"text":"Beans","stretch":True},
{"text":"Eggs","stretch":True},
{"text":"Spam","stretch":True},
{"text":"Eggs","stretch":True},]
self.rowdata=[]
self.table=ttkb.tableview.Tableview(master = self.window,
coldata=self.coldata,
rowdata=self.rowdata,
paginated=True,
searchable=True,
autofit=True)
#at this point, the table is nice and neat, and doesn't take up alot of space
#now add a button that will change
self.button=ttkb.Button(text="change data",command=self.change_data)
#pack table and button
self.table.pack()
self.button.pack()
self.window.mainloop()
def change_data(self):
self.rowdata = [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],]
self.table.build_table_data(coldata=self.coldata,rowdata=self.rowdata)
self.table.autofit_columns()
root=ttkb.Window()
MainAppWindow(root)
Hey ☺️ I finally got the solution ! Just call the reset_table() function after build_table_data() instead of autofit_columns() as shown :
import tkinter as tk
import ttkbootstrap as ttkb
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.constants import *
class MainAppWindow(ttkb.Window):
def __init__(self,root):
self.window = root
self.window.geometry('900x600')
#initialize table
self.coldata=[{"text":"Spam","stretch":True},
{"text":"Beans","stretch":True},
{"text":"Eggs","stretch":True},
{"text":"Spam","stretch":True},
{"text":"Eggs","stretch":True},]
self.rowdata=[]
self.table=ttkb.tableview.Tableview(master = self.window,
coldata=self.coldata,
rowdata=self.rowdata,
paginated=True,
searchable=True,
autofit=True)
#at this point, the table is nice and neat, and doesn't take up alot of space
#now add a button that will change
self.button=ttkb.Button(text="change data",command=self.change_data)
#pack table and button
self.table.pack()
self.button.pack()
self.window.mainloop()
def change_data(self):
self.rowdata = [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],]
self.table.build_table_data(coldata=self.coldata,rowdata=self.rowdata)
self.table.reset_table()
root=ttkb.Window()
MainAppWindow(root)
Happy coding 😄