我想在画布中创建一些文本:
myText = self.canvas.create_text(5, 5, anchor=NW, text="TEST")
现在如何找到myText的宽度和高度?
答案 0 :(得分:11)
bounds = self.canvas.bbox(myText) # returns a tuple like (x1, y1, x2, y2)
width = bounds[2] - bounds[0]
height = bounds[3] - bounds[1]
答案 1 :(得分:6)
如果您感兴趣的是所有您感兴趣的画布的宽度和高度,使用框的边界然后检查差异工作,如果您想这样做,这个方法似乎运行良好。
width = myText.winfo_width()
height = myText.winfo_height()