5
我想創建一個畫布一些文字:如何找出Python/Tkinter中畫布項的大小?
myText = self.canvas.create_text(5, 5, anchor=NW, text="TEST")
現在我怎麼會將myText找到的寬度和高度?
我想創建一個畫布一些文字:如何找出Python/Tkinter中畫布項的大小?
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]
如果您只關心所用畫布的寬度和高度,使用框的邊界,然後檢查差異化作品,如果您想要這樣做,則此方法似乎效果不錯。
width = myText.winfo_width()
height = myText.winfo_height()
`myText`,至少在給出的例子中是`int`。你給的行只會導致一個** AttributeError **被引發。 – 2016-10-17 11:14:30