2008-09-21 3 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 **를 일으킬뿐입니다. –

관련 문제