Skip to content
Sign upLog in
← Back to Community

Python Turtle using images

Profile icon
MartinOHanlon1

I wanted to use images with the Python turtle to set the turtle to be a different shape e.g.

my_turtle.shape(my_image.gif)

Unfortunately I couldnt find a way of adding images to a Python turtle project. Is this something which is supported?

Voters
Profile icon
Mustafaabduruf
Profile icon
Mindjoy
Profile icon
Himang
Profile icon
stevencarpenter
Profile icon
MartinOHanlon1
Comments
hotnewtop
Profile icon
PYer

Yes.

import turtle screen = turtle.Screen() image = "rocketship.png" screen.addshape(image) turtle.shape(image)

Just note that you need to do both the screen.addshape() and turtle.shape(), to set the shape of the turtle.
This wasn't part of your question, but you might want to know how to do this. You can change the background image of the screen to, as shown in this example.

import turtle screen = turtle.Screen() screen.setup(400, 400) screen.bgpic("space.jpg")

Make sure to set the screen.setup() size to the same size as your image. Otherwise, there will be white space around the edges.

Please upvote this comment if it was helpful or useful in anyway. Thank you!

Profile icon
PYer

@mat1
oops.

Profile icon
PYer

@mat1
We should tell timchen about this. So that he can allow it. And also couldn't you enter the image url

Profile icon
Adam983

ive tryed to do it but python doesnt operate with 2 inputs

Profile icon
argthe1st

I don't think so. Why would you want to change the shape of your turtle in the first place?

Profile icon
MartinOHanlon1

@argthe1st
so you can have cool spaceships rather than boring arrows!

You can also use the stamp() method to push a image onto the background.

Profile icon
JohnHunter3

yeah im pretty sure you'd have to use idle or something to import pictures.im trying to move one of my turtle projects to repl and since i cant add files (yet) we're probably going to have to use turtle.shape() and turtle.shapesize() to make graphics