I've created a treeview table in Tkinter Python, and filled it up with only one item so far. This item corresponds to the first row of the table. The color of this row is set to green. When the said row is selected by clicking on it, its color changes to blue, but when I click on an empty space in order to unselect the row and have it revert back to its original color, it doesn't work; it remains blue until I rerun the application, which is unpractical as a solution. Hence me asking for a better one.
Thanks to anybody willing to assist me in solving this issue.
Clicking on the empty space inside a Treeview
widget does not change the current selection.
Under default selectmode
, you can use Ctrl-click on the selected item to deselect it.
If you want to clear the selection when clicking the empty space, you can do it inside the callback on binding <Button-1>
event:
def on_click(event):
table = event.widget
item = table.identify_region(event.x, event.y)
if item == "nothing":
table.selection_set("") # clear selection
# assume table is the Treeview widget
table.bind("<Button-1>", on_click)