Turtle Subclass "object has no attribute '_shown'"
Asked Answered
L

0

2

New to Python here. I am messing around with Turtle module, and when I try to create a Turtle type class the following way I get the error message:

AttributeError: 'Buttons' object has no attribute '_shown'

My Python script:

import turtle

wn = turtle.Screen()
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0)

class Buttons(turtle.Turtle):
    def __init__(self, color, text):
        self.hideturtle()
        self.color(color)
        self.shape('square')
        self.shapesize(stretch_wid=3, stretch_len=7)
        self.penup()
        self.goto(0, 0)
        self.stamp()
        self.color('white')
        self.goto(0, 0 - FONT_SIZE/2)
        self.write(text, align='center', font=FONT)


t1 = Buttons("green", "start")

while True:
    wn.update()
Louise answered 10/8, 2020 at 17:52 Comment(5)
You failed to call the inherited __init__() method, so your subclass never received the initialization that would make it a functional Turtle. turtle.Turtle.__init__(self) would be one way of writing this.Saturday
What @Saturday is true. You can also do it using the slightly shorter super().__init__().Gynaecology
@jasonharper, you should post this as an answer, IMHO.Zacarias
I suggest not subclassing Turtle in the first place.Enfranchise
Related: Turtle Subclass "object has no attribute '_shown'"Enfranchise

© 2022 - 2024 — McMap. All rights reserved.