使用Python 3.2和tkinter。如何使Button-3(右键单击)选择鼠标光标悬停在Treeview小部件中的项目?我基本上希望Button-3事件以与当前单击左键相同的方式选择项目。
答案 0 :(得分:8)
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