I'm trying to implement autocompletion for Entry widget (or, rather, enhance the recipies already published by others). I want to make pop up appear next to insertion cursor. The problem is, I cannot find how to get the x/y coordinates of insertion cursor.
There is a similar question: The Tkinter Text Widget Insertion Cursor -- but it gives an answer for Text widget, which does not work for Entry.
The underlying Tk Entry
widget has a bbox
subcommand to get the coordinates of a specified item, as do Text
and a few other widgets, but for some reason Tkinter fails to implement it on this particular widget. (If you do try calling .bbox()
on an Entry
, you're actually executing .grid_bbox()
, which is something quite different.) However, you can usually work around missing Tkinter functionality by calling Tk directly:
entry._getints(entry.tk.call((entry, 'bbox', 'insert')))
(You can replace 'insert'
with various other forms of character index specification.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.