From: Kevin Walzer on
I'm trying to create a canvas that simply displays an image, but I'm
running into some difficulty with defining the image coordinates so the
image is fully displayed. Here's some sample code:

image create photo foo -file foo.png

pack [canvas .c -height [image height foo] -width [image width foo]
-fill both -expand no

..c create image 0 0 -tags item -image foo

This results in part of the image being displayed, part being cut off.
I've tried various coordinates, but I can't figure this out.

Is there a way to programatically set the coordinates of the image so it
fully displays, centered in the canvas (the canvas' height and width are
set to the same height and width of the image)?

Thanks,
Kevin
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
From: Kevin Walzer on
On 6/10/10 10:36 PM, Kevin Walzer wrote:
> I'm trying to create a canvas that simply displays an image, but I'm
> running into some difficulty with defining the image coordinates so the
> image is fully displayed. Here's some sample code:
>
> image create photo foo -file foo.png
>
> pack [canvas .c -height [image height foo] -width [image width foo]
> -fill both -expand no
>
> .c create image 0 0 -tags item -image foo
>
> This results in part of the image being displayed, part being cut off.
> I've tried various coordinates, but I can't figure this out.
>
> Is there a way to programatically set the coordinates of the image so it
> fully displays, centered in the canvas (the canvas' height and width are
> set to the same height and width of the image)?
>
> Thanks,
> Kevin

Looks like .c create image 0 0 -tags item -image foo -anchor nw (for the
upper left-hand corner) does the trick just fine.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
From: Aric Bills on
On Jun 10, 8:53 pm, Kevin Walzer <k...(a)codebykevin.com> wrote:
> On 6/10/10 10:36 PM, Kevin Walzer wrote:
>
>
>
> > I'm trying to create a canvas that simply displays an image, but I'm
> > running into some difficulty with defining the image coordinates so the
> > image is fully displayed. Here's some sample code:
>
> > image create photo foo -file foo.png
>
> > pack [canvas .c -height [image height foo] -width [image width foo]
> > -fill both -expand no
>
> > .c create image 0 0 -tags item -image foo
>
> > This results in part of the image being displayed, part being cut off.
> > I've tried various coordinates, but I can't figure this out.
>
> > Is there a way to programatically set the coordinates of the image so it
> > fully displays, centered in the canvas (the canvas' height and width are
> > set to the same height and width of the image)?
>
> > Thanks,
> > Kevin
>
> Looks like .c create image 0 0 -tags item -image foo -anchor nw (for the
> upper left-hand corner) does the trick just fine.
>
> --
> Kevin Walzer
> Code by Kevinhttp://www.codebykevin.com

For completeness, also add -borderwidth 0 -highlightthickness 0 to the
canvas options.