How to find out the size of a canvas element in Python / Tkinter?

I want to create some text in the canvas:

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

Now how to find the width and height of myText?

+5
source share
2 answers
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 link .

+10
source

This method seemed to work well if all you are interested in is the width and height of the canvas in question, using the borders of the field, and then checking the differential is just as good if you want to do it that way.

width = myText.winfo_width()  
height = myText.winfo_height()
+5
source

All Articles