Why is this attribute error here

Can someone tell me why this attribute error is here

from turtle import Turtle

class paddle(Turtle):
    def __init__(self, pos):
        self.shape("square")
        self.goto(pos)
        self.shapesize(stretch_wid=5, stretch_len=1)
        self.color("blue")

AttributeError: 'paddle' object has no attribute 'screen'

I’m not sure what kind of answer you expect. Apparently paddle class doesn’t have screen attribute. Should it have it? If yes, then it should be added, if not, then some other code should be changed to not expect it.

Firstly, you need to describe the problem in detail that you are facing. Also, try to add what you want to achieve. It helps us to understand the problem better.

As for your problem, you need to import Screen and add the screen attribute to your code end of the class.

screen = Screen()
screen.exitonclick()

Here is an example code that might help you to understand your problem. Cause I’m not sure what you want to achieve.

from turtle import Screen, Turtle

class MyTurtle(Turtle):
    def __init__(self, color, pensize, shape, speed):
        super().__init__(shape)
        self.color(color)
        self.pensize(pensize)
        self.speed(speed)

yertle = MyTurtle('blue', 2, 'turtle', 'fast')
yertle.circle(100)

screen = Screen()
screen.exitonclick()

I hope you solve the problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.