[Tkinter-discuss] Getting object Y pos in Canvas

Michael Lange klappnase at web.de
Sun Dec 18 17:30:05 CET 2011

Hi Martin,

Thus spoketh Martin B <spooky.ln at tbs-software.com> 
unto us on Sun, 18 Dec 2011 16:48:40 +0100:

> Hi all,
> For my little app i need know last Y coord of object i created on
> Canvas.
> I'm creating a text Object. For his last X coord i use
> font.measure('bla bla bla') this working.But i want know last Y coord
> coz i need create next text object bottom.
> How i get Y if i create this text object
> create_text(0, 0, anchor='nw', text='bla\n bla\n bla', font=boldfont)

The Canvas'es coords() method is your friend. From the canvas tk manpage:

pathName coords tagOrId ?coordList?
Query or modify the coordinates that define an item. If no coordinates
are specified, this command returns a list whose elements are the
coordinates of the item named by tagOrId. If coordinates are specified,
then they replace the current coordinates for the named item. If tagOrId
refers to multiple items, then the first one in the display list is used.

I hope this helps


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Captain's Log, star date 21:34.5...

More information about the Tkinter-discuss mailing list