Dqnny Dqnny - 2 months ago 18
Python Question

Python Turtle - Is it possible to prevent the crash at the end

this is my code. I am using the turtle module to just write some text on the screen for a project for school. But whenever I do this, the program crashes/stops responding and I was wondering if it is possible to prevent this from happening.

import turtle

screen = turtle.Screen()
screen.screensize(500, 500, "pink")

drawingpen = turtle.Turtle()
drawingpen.color("black")
drawingpen.penup()
drawingpen.setposition(-300, -300)
drawingpen.pendown()
drawingpen.pensize(3)
for side in range(4):
drawingpen.forward(600)
drawingpen.left(90)

drawingpen.hideturtle()

y = 243

for x in range(10):
drawingpen.penup()
drawingpen.color("black")
drawingpen.setposition(0, y)
drawingpen.pendown()
drawingpen.write("Test", False, align="center", font=("Arial", 18, "normal"))
drawingpen.hideturtle()
y = y - 57

Answer

Your code hasn't crashed, it just ran out of code to process. The code that is there is working fine and as expect.

To see what I mean add:

print("END")

to the end of your code. You will see the console prints the word "END" after your text is finished printing. But a nicer way might be to add:

screen.exitonclick()

to the end. This will close the window when you click on it.