[Tkinter-discuss] Sizing

Michael Lange klappnase at web.de
Mon Dec 25 01:53:59 CET 2006

On Sun, 24 Dec 2006 16:42:45 -0500
Jeff Cagle <jrcagle at juno.com> wrote:

> This is an ignorant question, so thanks in advance for your patience.
> I'm trying to code a card game, and I have lots of little .gif's used to 
> display card images as follows:
> from Tkinter import *
> import Image, ImageTk
> ...
> class Card(object):
>   def display(self, canvas, x, y, angle)
>      im = Image.open(self.URL)
>      im = im.rotate(angle)
>     self.image = ImageTk.PhotoImage(im)
>     canvas.create_image(x,y,image=self.image)
> ...
> The idea is to show four hands of 13 cards, each hand facing inwards.
> Oddly, when I display them, the right hand gets truncated.  The 
> dimensions of the canvas print out as 265x378.  I can fix it by 
> assigning height and width of the canvas manually, but it made me 
> wonder: why doesn't the canvas autosize?

Probably because it is not wanted in many cases that the size of the widget
increases when new items are added. Imagine a situation, where the bounding
box of all canvas item exceeds the screen dimensions. Or maybe you do not
want to resize the widget at all but use scrollbars instead.

For your problem it might be the best choice to check out the maximum
possible size of the canvas and apply this manually.

I hope this helps


More information about the Tkinter-discuss mailing list