2

This is my code :

import turtle             
wn = turtle.Screen()      
alex = turtle.Turtle()    

alex.forward(50)          
alex.left(90)             
alex.forward(30)          

wn.mainloop()             

And my error is: "_Screen object has no attribute mainloop"

I tried to do just "mainloop" but then I got NameError while doing alex.mainloop gave same error i.e. turtle object has no attribute mainloop.

Googling told me that I might have my file name as turtle.py creating the conflict but that's not the case.

2
  • In python 3, this works fine, so I assume this is py 2 only. I'm tagging as such but please let me know if I'm mistaken in that assumption. Commented Mar 4, 2023 at 16:38
  • Does this answer your question? AttributeError: '_Screen' object has no attribute 'mainloop' Commented Mar 4, 2023 at 16:38

1 Answer 1

1

You just need to call the mainloop() function on the turtle module. So your last line should be:

turtle.mainloop()
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works but I don't understand, why won't it work on the screen or turtle object?
It is very unclear from the documentation. The documentation of turtle.mainloop() has an example showing screen.mainloop().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.