Python/Tkinter에서 캔버스 항목의 크기를 어떻게 알 수 있나요?
-
02-07-2019 - |
문제
캔버스에 텍스트를 만들고 싶습니다.
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()
제휴하지 않습니다 StackOverflow