Using Python 3.2 and tkinter. How do you make the Button-3 (right click) select the item in a Treeview widget that the mouse cursor is hovering over? I basically want the Button-3 event to select the item in the same way as the current single left click does.
You half answered your own question. Just coded and tested my code, so thought no harm in posting my solution snippet here.
def init(self):
"""initialise dialog"""
# Button-3 is right click on windows
self.tree.bind("<Button-3>", self.popup)
def popup(self, event):
"""action in event of button 3 on tree view"""
# select row under mouse
iid = self.tree.identify_row(event.y)
if iid:
# mouse pointer over item
self.tree.selection_set(iid)
self.contextMenu.post(event.x_root, event.y_root)
else:
# mouse pointer not over item
# occurs when items do not fill frame
# no action required
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With