get the position / coordinates and size of text displayed on the screen in TKINTER get the position / coordinates and size of text displayed on the screen in TKINTER tkinter tkinter

get the position / coordinates and size of text displayed on the screen in TKINTER


If you use a canvas, with bbox you can return the bounding box of the items.

from Tkinter import *def callback(event, text_id):    print event.widget.bbox(text_id)root = Tk()canvas = Canvas(root, width=400, height=200)text = "the lazy dog jumped over the brown fox"offset = 20for word in text.split(" "):    text_id = canvas.create_text(offset, 50, text=word, anchor=W)    bbox = canvas.bbox(text_id)    offset += bbox[2] - bbox[0] + 5    canvas.tag_bind(text_id, "<Button-1>",                    lambda e, i=text_id: callback(e, i))canvas.pack()root.mainloop()