Python Forum
bind hover on tkinter.ttk.Treeview
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bind hover on tkinter.ttk.Treeview
#1
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
Reply
#2
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()
Reply
#3
Now if I could ever remember what I was writing in January.
I'll will use this!
Thanks
Reply
#4
Sorry. Perhaps too late, but I found your question 2 days ago, when I was looking for a solution for the same problem.
Reply
#5
Don't be sorry, need to keep on learning. This is a common enough thing that I will be
using it again soon.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? CyKlop 5 203 Oct-20-2021, 12:14 AM
Last Post: CyKlop
  tkinter - update/refresh treeview snakes 4 3,433 May-13-2021, 07:10 AM
Last Post: snakes
  [Tkinter] Glow text of clickable object on hover with transition andy 6 1,298 May-11-2021, 07:39 AM
Last Post: andy
  [Tkinter] bind lambda keypress counter knoxvilles_joker 15 2,010 Apr-19-2021, 01:56 AM
Last Post: knoxvilles_joker
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 1,170 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984
  [Tkinter] Mouse click without use bind ATARI_LIVE 8 2,729 Oct-23-2020, 10:41 PM
Last Post: ATARI_LIVE
  [Tkinter] Hover event DT2000 9 3,448 Apr-19-2020, 05:51 AM
Last Post: DT2000
  [Kivy] AttributeError: 'NoneType' object has no attribute 'bind' faszination_92 2 3,233 Apr-12-2020, 07:01 PM
Last Post: Larz60+
  [WxPython] Bind error PeterLinux 1 1,010 Apr-06-2020, 03:07 AM
Last Post: joe_momma
  Tkinter:Unable to bind and unbind function with a button shallanq 2 2,425 Mar-28-2020, 02:05 AM
Last Post: joe_momma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020