你们一半回答了自己的问题.刚刚对我的代码进行了编码和测试,因此在此处发布我的解决方案代码段并没有什么坏处.
def init(self):
"""initialise dialog"""
# Button-3 is right click on windows
self.tree.bind("", 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