I was recently following a tutorial on turtle in python version 2.7.11. The problem is, the window for turtle graphic does not show up and in the python shell it reads the file path and then "Restart". I have also reinstalled python and I'm on mac OS X.10.11.4
thank you
import turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
brad.forward(100)
brad.right(90)
window.exitonclick()
draw_square()
You should indent correctly. Make sure the line which calls draw_square()
should be outside of the function definition:
import turtle
def draw_square():
window = turtle.Screen()
window.bgcolor("red")
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("yellow")
brad.speed(2)
brad.forward(100)
brad.right(90)
window.exitonclick()
draw_square()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.