How can I import an image in Python Turtle?

前端 未结 5 1721
时光说笑
时光说笑 2021-01-24 10:47

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

相关标签:
5条回答
  • 2021-01-24 11:18

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

    0 讨论(0)
  • 2021-01-24 11:19

    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)

    0 讨论(0)
  • 2021-01-24 11:25

    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

    0 讨论(0)
  • 2021-01-24 11:28

    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 讨论(0)
  • 2021-01-24 11:36

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

    0 讨论(0)
提交回复
热议问题