Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turtle module - Saving an image

I would like to figure out how to save a bitmap or vector graphics image after creating a drawing with python's turtle module. After a bit of googling I can't find an easy answer. I did find a module called canvas2svg, but I'm very new to python and I don't know how to install the module. Is there some built in way to save images of the turtle canvas? If not where do I put custom modules for python on an Ubuntu machine?

like image 616
jjclarkson Avatar asked Nov 01 '10 17:11

jjclarkson


People also ask

What does Penup () do in turtle?

penup or pu means pick pen up, so you can move turtle without leaving tracks. pendown or pd means pick pen down, so you can move the turtle and leave tracks.

What does turtle Begin_fill () do?

begin_fill() This method is used to call just before drawing a shape to be filled. It doesn't take any argument.


1 Answers

from tkinter import *  # Python 3 #from Tkinter import *  # Python 2 import turtle   turtle.forward(100) ts = turtle.getscreen()  ts.getcanvas().postscript(file="duck.eps") 

This will help you; I had the same problem, I Googled it, but solved it by reading the source of the turtle module.

The canvas (tkinter) object has the postscript function; you can use it.

The turtle module has "getscreen" which gives you the "turtle screen" which gives you the Tiknter canvas in which the turtle is drawing.

This will save you in encapsulated PostScript format, so you can use it in GIMP for sure but there are other viewers too. Or, you can Google how to make a .gif from this. You can use the free and open source Inkscape application to view .eps files as well, and then save them to vector or bitmap image files.

like image 57
KilyenOrs Avatar answered Sep 27 '22 02:09

KilyenOrs