How can I import an image in Python Turtle?

Question:

What I want, is to get an image to replace the default turtle, just like it is done here: http://blog.trinket.io/using-images-in-turtle-programs/.

This is my code, but I don’t know why it doesn’t work:

import turtle

image = "C:/Python27/Pythonprogramming/image.png"
screen = turtle.Screen()

screen.addshape(image)
turtle.shape(image)

turtle.mainloop()

This is all in effort to make a turtle that’s actions can be manipulated through Python code. I have searched all over the internet, but can’t seem to find a solution.

Asked By: Izak the coder

||

Answers:

I’m not sure but I think on Windows ,the paths will be like this:
“C:Python2Pythonprogrammingimage.png”
Also , what error does it raise exactly?

Answered By: user7111497

The turtle graphics has support for .gif images only. Please try to change your image’s format.

Here’s a link to a similar question How can i add an image (Python)

Answered By: HENOK MILLION

You can take screenshot of the pic and can convert/resize to .gif at ezgif.com.

Background:

win = turtle.Screen()
win.bgpic('background.gif') # or whatever the file name in the directory.

Using Shapes:

win.register_shape('pic1.gif')
rocket = turtle.Turtle()
rocket.shape('pic1.gif')

Simple example game:

https://www.youtube.com/watch?v=sRnSJvSHgBs&t=4s

Answered By: Jean Joubert

Trinket is a program for python! You have to type your code in trinket if you want that code to work!

Answered By: Dan Cod

this picture must be in the same folder with doc.py . And then you can write name of the picture: img.gif

Answered By: yurew

OMG I remember! Use Pygame! Sorry

Answered By: Dan Cod