문제

캔버스에 텍스트를 만들고 싶습니다.

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

이제 myText의 너비와 높이를 어떻게 찾을 수 있나요?

도움이 되었습니까?

해결책

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

참조 TkInter 참조.

다른 팁

관심 있는 것이 캔버스의 너비와 높이뿐이라면 이 방법은 잘 작동하는 것 같았습니다. 상자의 경계를 사용한 다음 차이를 확인하면 그렇게 하려는 경우에도 잘 작동합니다.

width = myText.winfo_width()  
height = myText.winfo_height()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top