How do I find out the size of a canvas item in Python/Tkinter?

Matt Gregory picture Matt Gregory · Sep 21, 2008 · Viewed 8.4k times · Source

I want to create some text in a canvas:

myText = self.canvas.create_text(5, 5, anchor=NW, text="TEST")

Now how do I find the width and height of myText?

Answer

skymt picture skymt · Sep 21, 2008
bounds = self.canvas.bbox(myText)  # returns a tuple like (x1, y1, x2, y2)
width = bounds[2] - bounds[0]
height = bounds[3] - bounds[1]

See the TkInter reference.