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 - update/refresh treeview snakes 5 20,534 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [Tkinter] How to insert data json to treeview tkinter? Shakanrose 8 4,208 Jan-19-2023, 03:58 PM
Last Post: Shakanrose
  [Tkinter] Different rows colours in treeview tkinter Krissstian 1 1,187 Nov-20-2022, 09:59 PM
Last Post: woooee
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,448 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [Tkinter] bind menator01 1 1,234 Apr-15-2022, 08:47 PM
Last Post: menator01
  [Tkinter] About Tkinter Treeview.selection_get() usage. water 3 8,149 Feb-12-2022, 02:19 PM
Last Post: water
  [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? CyKlop 5 3,303 Oct-20-2021, 12:14 AM
Last Post: CyKlop
  [Tkinter] Glow text of clickable object on hover with transition andy 6 5,910 May-11-2021, 07:39 AM
Last Post: andy
  [Tkinter] bind lambda keypress counter knoxvilles_joker 15 7,624 Apr-19-2021, 01:56 AM
Last Post: knoxvilles_joker
  [Tkinter] acceleration of data output in treeview tkinter Vladimir1984 4 4,096 Nov-21-2020, 03:43 PM
Last Post: Vladimir1984

Forum Jump:

User Panel Messages

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