Search code examples
pythonturtle-graphicsattributeerrorpython-turtle

How do I add an image to the turtle screen without getting an error?


I have seen other people ask this question and I have looked it up. However, I still get the same error. Error: 'str' object has no attribute '_type'. Here is my code:

from turtle import *
setup(600,600)
Screen()
sc = Screen()
alien = os.path.expanduser("~/Desktop/AlienGameImage.gif")
sc.register_shape(alien)
t = Turtle()
t.shape(alien)
mainloop()

I have also tried:

sc.addshape(alien)

Solution

  • tried your code and i had the same error, with few changes it worked perfectly for me :

    from turtle import *
    sc = Screen()
    sc.setup(600,600)
    alien = r"folder\giftest.gif"
    sc.register_shape(alien)
    t = Turtle()
    t.shape(alien)
    mainloop()