python tkinter treeview right click (Button-3) event to select item in treeview python tkinter treeview right click (Button-3) event to select item in treeview tkinter tkinter

python tkinter treeview right click (Button-3) event to select item in treeview


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