I am using the tkinter Treeview
widget to show a database. The command when clicking on one of the headings is used for sorting the table based on the clicked column.
Additionally I want a tooltip box show up as soon as I hover (or right click) over one of the headings. The tooltips aren't a problem for other widgets but the heading of a treeview isn't a full widget of course.
How can I bind any action to the headings except for the usual command?
You can bind the events to the treeview widget itself. The widget has a method named identify which can be used to determine which part of the treeview the event occurred over.
For example:
Use the
tree.heading
command as proposed by Mihail above, but note that if you are running from within aclass
, you'll need to pass a self into the method as usual.Here is a Python 2 snippet that will load a treeview and demonstrate calling both a method and an external function:
Note for some reason, the first click doesn't seem to work immediately but gets stuck in the buffer until you click a second time - very eager to hear anyone with an explanation for this.
use -command in config: