Trying to draw a straight line using
import turtle
def draw_line():
window =turtle.Screen()
window.bgcolor("blue")
animal=turtle.Turtle ()
animal.forward(100)
window.exitonclick()
draw_line()
but the shell keeps restarting and doesn't run the code. Help!
I tried to run your code as follows:
import turtle
def draw_line():
window = turtle.Screen()
window.bgcolor('blue')
animal = turtle.Turtle()
animal.forward(100)
window.exitonclick()
draw_line()
And I can successfully run it.
I saved the above code in a file called turtle_test.py
and ran it on the command line like this:
python turtle_test.py
For me that opens a new window with the expected output and it closes on click.
I tried it with both Python 2.6 and Python 3.5. Neither version had a problem with this script. One thing I have to mention though is that the window created by this script did not get focus automatically. I had to find it by Alt-Tab'ing, maybe that's your problem as well?
Also sorry for answering without a definitive answer, but it seems I need 'points' to be able to post a comment..
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.