[Python] How to set an image for class that inherits Turtle

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    What I am trying to do is create a class called Meteor() which inherits from the turtle.Turtle() class. My current code is this:

    from turtle import Turtle


    class Meteor(Turtle):
    def __init__(self, health):
    Turtle.__init__(self)
    self.health = health


    I am trying to somehow make my Meteor() class have a shape of an image of a meteor. I tried this:

    class Meteor(Turtle):
    def __init__(self, health):
    Turtle.__init__(self)

    self.health = health
    self.image = tkinter.PhotoImage('Spinning-asteroid-6.gif')
    Screen().register_shape('meteor', Shape('image', self.image))
    self.shape('meteor')


    But when I call Meteor() in my main file, the turtle does not appear.

    Continue reading...

Compartilhe esta Página