[英]how to create a pop up menu which is linked with listbox in tkinter?
列表框的curselection
方法将返回所选项目的列表。 列表框的bbox
方法将给出项目相对于列表框本身的坐标。 您可以使用winfo_rootx
和winfo_rooty
来获取屏幕上列表框的绝对坐标。 您可以使用所有这些信息将菜单放置在所选项目附近。
例如:
def show_popup(event):
selection = event.widget.curselection()
if selection:
item = selection[0]
rootx = event.widget.winfo_rootx()
rooty = event.widget.winfo_rooty()
itemx, itemy, itemwidth, itemheight = event.widget.bbox(item)
popup_menu.tk_popup(rootx+event.widget.winfo_width()-10, rooty+itemy+10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.