1

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.

Thanks in advance for any help!

Izak the coder
  • 35
  • 1
  • 2
  • 6

6 Answers6

0

I'm not sure but I think on Windows ,the paths will be like this: "C:\Python2\Pythonprogramming\image.png" Also , what error does it raise exactly?

0

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)

Community
  • 1
  • 1
0

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

slfan
  • 8,665
  • 115
  • 63
  • 77
0

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

Dan Cod
  • 11
  • 1
0

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

yurew
  • 1
0

OMG I remember! Use Pygame! Sorry

Dan Cod
  • 11
  • 1
  • Please provide more details. How would Pygame solve the problem? – Ian Thompson May 12 '22 at 15:14
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 12 '22 at 15:14
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31755365) – James Barnett May 16 '22 at 15:16