Python Turtle Module- Saving an image

后端 未结 2 857
天涯浪人
天涯浪人 2020-12-09 02:08

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 eas

2条回答
  •  醉梦人生
    2020-12-09 02:19

    from Tkinter import *
    from turtle import *
    import 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.

提交回复
热议问题