How big is that canvas in the window?

Joseph Andrew Knapka jknapka at
Sat Aug 25 05:22:57 CEST 2001

Bob Greschke wrote:
> Here's the idea:
> It's in Python/Tkinter.  See the "Plot" button?  I want to draw a
> graph in the black area.  How do I find out the dimensions of the
> black canvas area???  I can make a guess when I first draw everything
> by setting the size of everything, but I don't want to do that.  I
> want the user to be able to resize the window and then redraw the
> graph.  I got to exactly this same point in GTK+ and had to give up.
> Am I going to have to write this program in Java?? :-)
> (The program is actually being written for/on a UNIX box.  I just had
> to use a Windows machine to get the screen dump.)
> Thanks!
> Bob

I can't view the URL you reference for some reason, but I'll
take a shot at answering your question.

The canvas object is always -logically- the same size: whatever
values you give for the "width" and "height" options when the
canvas was created. It will be clipped if the containing window
is smaller than the canvas, but the contents of the clipped
areas are "still there" (they'll be repainted if they become
visible again). The upshot of all this is that you can just draw
using absolute canvas coordinates and everything will work.
If you need to find out the (canvas) coordinates of a particular
item on the canvas, use "canvas.bbox(<item>)". If you need the
canvas to be scrollable, attach scrollbars to it and hook
them up using the xscrollcmd/yscrollcmd/xview/yview options.

Does that help?

# Joe Knapka
# "You know how many remote castles there are along the
#  gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald
# Linux MM docs:

More information about the Python-list mailing list