[Image-SIG] Re: Problem in storing tkinter canvas as PNG file usingImageGrab.grab

Fredrik Lundh fredrik at pythonware.com
Wed Jun 25 23:14:04 EDT 2003


Suresh Kumar wrote:

>       Iam using python2.2/tkinter/windows. I have drawn some
> rectangles in my canvas. Now I want to store my canvas as a PNG
> file. Iam using "ImageGrab"  to grab the canvas. Iam getting the
> result as i expected when the canvas size is less than
> "canvas.winfo_width" and "canvas.winfo_height". But when the
> size larger than that, iam not getting the entire canvas image.

I'm not sure I follow -- are you trying to say that you've created a
canvas that's larger than the screen?

Obviously, the ImageGrab approach doesn't work in that case, since
it copies pixels from the display.  Some alternatives:

- use the Postscript generation mechanisms provided by the Canvas
widget, and use Ghostscript or some other postscript renderer to con-
vert from postscript to PNG.

- or with more work, but less dependencies, use PIL's ImageDraw module
(or some other 2D drawing interface) and re-render the canvas contents
directly into a pixmap.

- or scroll the canvas around (xview, yview), use the update method to
make sure it's redrawn, and use ImageGrab to cut out the pieces, and
paste them into a full-size image.

</F>






More information about the Image-SIG mailing list