I have a dataframe being displayed in a gui as a table using pandastable. I would like to have this table be frequently updates as new data becomes available (which updates the dataframe columns).
So I wrote this simple example to illustrate the point:
I create the dataframe df, then update it twice in the program by waiting 5 secs between each updates. I expect the GUI to appear then the contents to be updated at the same cadence. Instead the program execute with only the final dt value showing up in the table.
I tried to use .update() and .redraw() instead of .show() to update the values but that didn't work either.
Your input is much appreciated!
import pandas as pd
import tkinter as tk
from pandastable import Table
import time
df = pd.DataFrame({
'A': [1,1,1,1,1,1,],
'B': [1,1,1,1,1,1,],
'C': [1,1,1,1,1,1,],
'D': [1,1,1,1,1,1,],
})
root = tk.Tk()
root.title('PandasTable Example')
frame = tk.Frame(root)
frame.pack(fill='both', expand=True)
pt = Table(frame, dataframe=df)
pt.show()
time.sleep(5)
df = pd.DataFrame({
'A': [2,2,2,2,2,2,],
'B': [2,2,2,2,2,2,],
'C': [2,2,2,2,2,2,],
'D': [2,2,2,2,2,2,],
})
pt.model.df = df
pt.show()
time.sleep(5)
df = pd.DataFrame({
'A': [3,3,3,3,3,3,],
'B': [3,3,3,3,3,3,],
'C': [3,3,3,3,3,3,],
'D': [3,3,3,3,3,3,],
})
pt.model.df = df
pt.show()
root.mainloop()