pandastable in Tkinter GUI not rendering correctly after updating table and moving to the final row

72 Views Asked by At

I have an application that displays real-time data in a pandastable inside of a Tkinter application.

When the data updates, so does the table. However, I added some code so that after an update it automatically shows the final rows in the table.

When the data updates, the table does not render correctly. It shows one empty row. However, as soon as I scroll the table, all the rows suddenly appear.

I can not use df.tail because then I can not see the rows above the specified tail.

Here is the table after updating:

Here is the table after updating

Here is the table after scrolling:

Here is the table after scrolling

Here is the function. Since adding the final 2 lines I have had this issue. Without those 2 lines, the table updates and then renders correctly. However, it always starts at row 1, when I want the final row to be displayed (hence the 2 new lines of code).

def display_data(self, dataframe):
    if dataframe is None or dataframe.empty:
        print("No dataframe to display or dataframe is empty.")
        return  # Exit the function early if there's no dataframe or it's empty

    for widget in self.table_frame.winfo_children():
        widget.destroy()

    self.table = Table(self.table_frame, dataframe=dataframe, showtoolbar=False, showstatusbar=True, height=400, width=800)
    self.table.autoResizeColumns()
    self.table.show()
    self.table.redraw()

    # Find the last row index
    last_row_index = len(dataframe) - 1

    # Scroll to the last row
    self.table.movetoSelection(row=last_row_index)  # Assuming you want to scroll to the first column as well
1

There are 1 best solutions below

2
Mougnou On

Maybe try to use after to wait the full rendering of your table :

self.table.after(100, lambda: self.table.movetoSelection(row=last_row_index))

Also consider threading the whole process to prevent freezing GUI