2008-09-21 99 views

回答

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

查看TkInter reference

5

如果您只關心所用畫布的寬度和高度,使用框的邊界,然後檢查差異化作品,如果您想要這樣做,則此方法似乎效果不錯。

width = myText.winfo_width() 
height = myText.winfo_height() 
+0

`myText`,至少在給出的例子中是`int`。你給的行只會導致一個** AttributeError **被引發。 – 2016-10-17 11:14:30