Getting object Y pos in Canvas

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting object Y pos in Canvas

Martin B.-4
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)

thanks
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Getting object Y pos in Canvas

Michael Lange
Hi Martin,

Thus spoketh Martin B <[hidden email]>
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

Michael

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

Captain's Log, star date 21:34.5...
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Getting object Y pos in Canvas

Martin B.-4
In reply to this post by Martin B.-4
V Sun, 18 Dec 2011 16:48:40 +0100
Martin B <[hidden email]> napsáno:

sry i forgot add tag to object.
now i get bounding box of objects with canvas.bbox('mytag')

sry once more.

> 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)
>
> thanks
> _______________________________________________
> Tkinter-discuss mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/tkinter-discuss

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Getting object Y pos in Canvas

Michael Lange
Thus spoketh Martin B <[hidden email]>
unto us on Sun, 18 Dec 2011 17:32:34 +0100:

> V Sun, 18 Dec 2011 16:48:40 +0100
> Martin B <[hidden email]> napsáno:
>
> sry i forgot add tag to object.
> now i get bounding box of objects with canvas.bbox('mytag')
>

Oops, sure you're right, it must be bbox() not coords()

(^.^;)

Michael


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

Vulcans worship peace above all.
                -- McCoy, "Return to Tomorrow", stardate 4768.3
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss