turtle dump

alex23 wuwei23 at gmail.com
Thu Jul 16 07:50:29 EDT 2009


On Jul 16, 9:18 pm, superpollo <u... at example.net> wrote:
> lol. ;-) the title was indeed supposed to stir a bit of curiosity upon
> the reader...

Which isn't really useful when trying to obtain assistance... you want
certainty, not curiosity.

> in fact i was looking for a *platform independent* way to draw into a
> graphics file (say, a postscript or a png) using the turtle module. so i
> understand that "dumping a window" is not a good expression... maybe
> "redirecting graphics commands to a file instead of a window"?

You didn't actually answer Diez question. The turtle module is only a
recent (2.6/3.0) addition to Python and is probably obscure enough not
to have tracked across everyone's radar.

So _if_ you're talking about the standard lib turtle module, you're
not looking to 'dump a window', you're looking to write the contents
of turtle.Canvas to file. Canvas only supports writing to postscript,
so you'll have to do something like this (untested):

import turtle
screen = turtle.Screen()
# go go gadget turtle...
screen._canvas.postscript(file='turtle.ps')

Or it may be open('turtle.ps','w').write(screen._canvas.postscript
())... I couldn't find a definitive answer. Try looking through the Tk
docs, it should be covered there.

Note that this is a postscript _text_ file, so you'll also need to
find something to render it with.

Hope this helps point you in the right direction.



More information about the Python-list mailing list