Tkinter文本小部件插入光标
问题描述:
是否可以在Tkinter Text小部件中获取插入光标的y坐标?我正在尝试制作一个在插入光标旁边弹出的弹出菜单.
Is it possible to get the x y coordinates of the insertion cursor in a Tkinter Text widget? I'm trying to make a popup menu that pops up next to the insertion cursor.
答
bbox
方法可用于获取索引的边界框.您可以使用它来获取相对于窗口的位置.您可以使用winfo
方法获取窗口的x/y.
The bbox
method can be used to get the bounding box of an index. You can use that to get the position relative to the window. You can use the winfo
method to get the x/y of the window.
通常弹出窗口显示在鼠标旁边,而不是插入点旁边(尽管通常情况下,右键单击会先设置插入点,然后显示菜单).
Typically popups appear next to the mouse rather than the insertion point (though typically, right-clicking first sets the insertion point and then displays a menu).