ragardner / tksheet

Python tkinter table widget for displaying tabular data
https://pypi.org/project/tksheet/
MIT License
408 stars 50 forks source link

Cell highlights disappear when clicking in other cells #187

Closed joschkazj closed 1 year ago

joschkazj commented 1 year ago

Thanks for creating tksheet it is really great to have a flexible table widget available in Python + Tk!

I am using tksheet v6.2.0 and updating table cells based on results of a processing thread: the results are stored in the application class and an update method calls highlight_cells to set background colors:

    def update_part_view(self):
        # ...
        for idx, result in enumerate(self.all_assessments.values()):
            try:
                # Highlight current entry
                self.parts_table.highlight_cells(row=idx, column=0,
                                                 bg=colors[result.assessment],
                                                 redraw=True)
            except IndexError:
                # Table not filled (non-interactive usage or testing)
                pass

        self.parent.after(0, self.parent.update_idletasks)

at first, this results in the expected display: image but as soon as I select another cell (same happens for one of the highlighted cells) the colors disappear again: image

Before I dive too deep into this issue - does this behavior sound familiar to any of you and how could I fix it? As far as I've seen, the cell highlighting/color assignment is not undone anywhere else in the code - I still wonder what the correct way of updating the table widget display is: is it sufficient to trigger Tk's .update_idletasks() or do I need to explicitly call .refresh() on the table?

I've checked the display of the color example from the docs and there the background colors remain even after selecting and/or editing a cell.

Thanks in advance for any pointers or suggestions!

joschkazj commented 1 year ago

This appears to be another case of rubber-ducking: while investigating the issue I searched my application code for lines that called Tk's .update() method and replaced them with calls to .update_idletasks() which immediately solved the issue with cell display.

Apparently an ongoing update after populating my table widget interfered with the widget modifications/styling.