How to save a bitmap or vector graphics image after creating a drawing with python s turtle module

+1 vote
How to save a bitmap or vector graphics image after creating a drawing with python's turtle module.
Jul 6, 2019 in Python by Neel
7,369 views

1 answer to this question.

+2 votes

This worked for me:

from Tkinter import *
from turtle import *
import turtle

forward(100)
ts = turtle.getscreen()

ts.getcanvas().postscript(file="duck.eps")
answered Jul 6, 2019 by Kyraa
where does that get saved(if it does)
It gets saved in encapsulated PostScript format inside your python project folder.

I tried your code, but I got :

from Tkinter import *

ModuleNotFoundError: No module named 'Tkinter'

But if I use

import tkinter      I don't get the same error.

Also

forward(100)
ts = turtle.getscreen()
ts.getcanvas().postscript(file="NiceHexSpiral.eps")

I get:
NameError: name 'forward' is not defined

Here is my code:

import tkinter
import turtle

t=turtle.Pen()
turtle.bgcolor('dimgrey')
sides = 4
colors=['lemon chiffon', 'purple', 'blue', 'salmon', 'green', 'red']
y = 350

for x in range(y):
     t.pencolor(colors[x%sides])
     t.width(x*sides/200)
     t.forward(x*3/sides +x)
     t.left(y/sides+1)

forward(100)
ts = turtle.getscreen()
ts.getcanvas().postscript(file="NiceHexSpiral.eps")

Hi@OceansBlue,

There is nothing called the Tkinter module. You need to use tkinter. In your second error, you have used one function named forward. But you didn't define the function. So create your function or remove the function name. Make these changes and if you get any error, then paste the error here.

Corrected to tkinter and code worked without the need to create the function forward.

as it seems it is part of the tkinter package.

However, the code got saved as eps file, but i don't find it useful, as there is no image displayed.

So what is a better solution?
Hi@OceanBlue,

It depends on the format. Try with different formats and see what happens.

Related Questions In Python

0 votes
0 answers
0 votes
2 answers

How do I convert text file to CSV file with only plain python. Meaning no panda or any other special module?

Steps to Convert Text File to CSV ...READ MORE

answered Oct 15, 2020 in Python by Abdul Shekh
8,268 views
+1 vote
2 answers

How to resize the image canvas to maintain a square aspect ratio

down voteacceptedUsing OpenCVYou can use resize() in OpenCV to ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points

edited Jul 11, 2023 by Khan Sarfaraz 1,252 views
0 votes
1 answer

How to hide a window in the constructor immediately after creation?

You can use QtCore.QTimer class Example(QWidget):     def __init__(self, app):         QWidget.__init__(self)         QTimer.singleShot(0, ...READ MORE

answered Apr 17, 2018 in Python by anonymous
546 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,418 views
0 votes
1 answer

How to find out which functions a Python module contains?

Yes, you can do this. Python allows ...READ MORE

answered May 14, 2019 in Python by Raj
1,428 views
+1 vote
1 answer

How to install a module in Python 3.6 ?

If you are using Ubuntu then the ...READ MORE

answered Jun 25, 2019 in Python by Arvind
• 3,040 points
951 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP