Reputation: 263
I have a ttk Treeview (in a Frame in a Tk)) and a tk Listbox (in a Toplevel). My intention is to do the following:
Right now I can set the focus of the Toplevel when an unpressed mouse enters. I used .bind("<Enter>")
.
When I use .bind("<B1-Motion>")
I can detect movement of a pressed mouse. But only if I pressed the mouse within the list.
When I use.bind("<B1-Enter>")
I don't get any events.
How can I detect if a somewhere else pressed mouse enters my Listbox?
Upvotes: 3
Views: 2131
Reputation: 386275
You will need to set a binding on <B1-Motion>
. Then, in the callback you can use the winfo_containing
method to determine which widget is under the cursor. You can use event.x_root
and event.y_root
as arguments to winfo_containing
to find the widget:
self.bind_all("<B1-Motion>", self.on_motion)
...
def on_motion(self, event):
widget = self.winfo_containing(event.x_root, event.y_root)
...
Upvotes: 8