使用Python 3.2和tkinter。如何让-3\f25 Button-3 (右击)选择鼠标光标悬停在Treeview部件中的项目?基本上,我希望Button-3事件选择项目的方式与当前单击鼠标左键的方式相同。
发布于 2014-08-09 17:21:07
你自己回答了一半的问题。我只是对我的代码进行了编码和测试,所以我认为在这里发布我的解决方案片段没有什么坏处。
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
passhttps://stackoverflow.com/questions/12043942
复制相似问题