In python AttributeError: ‘function’ object has no attribute ‘exitonclick’ we face this error message when we import Screen Capital S from turtle and convert screen variable [small s ] then we need to use value screen [ small s ] but we use Screen [Capital S ] then the python interpreter shows this error message, If you want to fix this error you need to just remove Screen [Capital S ] and type screen [small s ], For more clarification, see the below example.
Wrong Code
import turtle
from turtle import Screen
screen = Screen()
turtle.shape("turtle")
turtle.color("red")
# Step 2 set turtle starting position
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.pensize(5)
# Step 3 Draw a heart shape
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
turtle.circle(-112, 200)
turtle.setheading(60)
turtle.circle(-112, 200)
turtle.forward(224)
turtle.end_fill()
Screen.exitonclick()
Error Massage
Traceback (most recent call last):
File "/home/kali/python/webproject/error/main.py", line 23, in <module>
Screen.exitonclick()
AttributeError: 'function' object has no attribute 'exitonclick'
Wrong code line
Screen.exitonclick()
Correct code line
screen.exitonclick()
- Wrong action: Screen [Capital S ].
- Correct action: screen [small s ].
Entire Correct Code line
import turtle
from turtle import Screen
screen = Screen()
turtle.shape("turtle")
turtle.color("red")
# Step 2 set turtle starting position
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.pensize(5)
# Step 3 Draw a heart shape
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
turtle.circle(-112, 200)
turtle.setheading(60)
turtle.circle(-112, 200)
turtle.forward(224)
turtle.end_fill()
screen.exitonclick()
What is NameError: name ‘screen’ is not defined. Did you mean: ‘Screen’?
In python we face this error message when we import Screen Capital S from turtle and convert screen variable [small s ] then we need to use value screen [ small s ] but we use Screen [Capital S ] then the python interpreter shows this error message.
How to fix NameError: name ‘screen’ is not defined. Did you mean: ‘Screen’?
If you want to fix this error you need to just remove Screen [Capital S ] and type screen [small s ], For more clarification, see the above example.
For more information Visit YouTube Channel.