bind hover on tkinter.ttk.Treeview - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: bind hover on tkinter.ttk.Treeview (/thread-1695.html) |
bind hover on tkinter.ttk.Treeview - Larz60+ - Jan-21-2017 I have been trying to find an example that shows how to bind mouse over Treeview cell without much success. I thought that '<Enter>' could be used, but that is on the widget level, not the cell level Perhaps I am not working my search correctly, but I can't find a single example or discussion on the subject I can't remember all that I have tried, but the one I thought would work was 'hover + tkinter.ttk.Treeview' This looked promising (and still may be), but the entry for Treeview, has no mention of active color. However, there is mention in spinbox, and other widgets, and I haven't tried that, so I will do that next. In the mean time, if anyone has an example, I'd love to see it. Thanks Larry RE: bind hover on tkinter.ttk.Treeview - hugo_chillon - May-19-2017 import tkinter as tk import tkinter.ttk as ttk class TreeBuilder(): def __init__(self, parent): self.parent = parent self.build() def build(self): self.tree = ttk.Treeview(self.parent) self.tree["columns"]=("one","two") self.tree.column("one", width=100 ) self.tree.column("two", width=100) self.tree.heading("one", text="coulmn A") self.tree.heading("two", text="column B") self.tree.insert("" , 0, text="Line 1", values=("1A","1b")) id2 = self.tree.insert("", 1, "dir2", text="Dir 2") self.tree.insert(id2, "end", "dir 2", text="sub dir 2", values=("2A","2B")) # or alternatively: self.tree.insert("", 3, "dir3", text="Dir 3") self.tree.insert("dir3", 3, text=" sub dir 3",values=("3A"," 3B")) # Here begins the key step self.tree.tag_configure('focus', background='yellow') self.tree.bind("<Motion>", self.mycallback) self.last_focus = None # ................................................ self.tree.pack() def mycallback(self, event): _iid = self.tree.identify_row(event.y) if _iid != self.last_focus: if self.last_focus: self.tree.item(self.last_focus, tags=[]) self.tree.item(_iid, tags=['focus']) self.last_focus = _iid if __name__=='__main__': root = tk.Tk() tree = TreeBuilder(root) root.mainloop() RE: bind hover on tkinter.ttk.Treeview - Larz60+ - May-20-2017 Now if I could ever remember what I was writing in January. I'll will use this! Thanks RE: bind hover on tkinter.ttk.Treeview - hugo_chillon - May-20-2017 Sorry. Perhaps too late, but I found your question 2 days ago, when I was looking for a solution for the same problem. RE: bind hover on tkinter.ttk.Treeview - Larz60+ - May-20-2017 Don't be sorry, need to keep on learning. This is a common enough thing that I will be using it again soon. |