2

This python program freezes and then stops responding whenever I run it.

I have looked at questions on the topic before and I have tried several script changes, but nothing worked.

This is the script I wrote:

import turtle
import os

wn =turtle.Screen()
wn.bgcolor("black")
wn.title("Space Invaders")

spaceship=turtle.Turtle()
spaceship.shape("triangle")
spaceship.color("blue")
spaceship.penup()
spaceship.setheading(90)
spaceship.speed(0)
spaceship.setposition(0,-260)

#border
borderpen=turtle.Turtle()
borderpen.color("white")
borderpen.penup()
borderpen.speed(0)
borderpen.setposition(-270,-270)
borderpen.pendown()
borderpen.hideturtle()

for side in range(4):
borderpen.fd(540)
borderpen.lt(90)



input('Press ENTER to exit')

For all I know there are no errors in script. Could it be that python does not run correctly on my computer?

I tried changing a few things in the script here and there, and nothing worked. Also I added functions to move the triangle turtle, but it did not work, so I removed the functions. What could be causing this?

Some additional information:

It's running on Windows 7.

I'm using PyCharm 2020.1 as IDE.

The Python version is 3.8.2

The error message when forcing to close the turtle window is:

Description: A problem caused this program to stop interacting with Windows. Problem signature:

Problem Event Name: AppHangB1

Application Name: python.exe

Application Version: 3.8.2150.1013

Application Timestamp: 5e55a3ed

Hang Signature: c6d0

Hang Type: 0

OS Version: 6.1.7601.2.1.0.768.3

Locale ID: 1036

Additional Hang Signature 1: c6d04898adfe72bcecd0e728a9229bc4

Additional Hang Signature 2: c79c

Additional Hang Signature 3: c79c374547b3b7b755a9988556a2666b

Additional Hang Signature 4: c6d0

Additional Hang Signature 5: c6d04898adfe72bcecd0e728a9229bc4

Additional Hang Signature 6: c79c

Additional Hang Signature 7: c79c374547b3b7b755a9988556a2666b

  • Cannot reproduce. Seems to work fine on my computer. The code runs, the window appears, does some stuff, then stops and exits once I provide the input. How are you running this code? Please provide more information about your environment. – Mihai Chelaru Apr 20 '20 at 17:24
  • Yeah @Mihai is right, you need to give us some more information about your python environment. – Harshit Ruwali Apr 20 '20 at 17:42
  • Okay, I added more information to the original post. Do you need more information? It would be interesting to understand why this is happening. – Tricky Devil Apr 20 '20 at 19:01
  • 1
    Now that you've added a sufficient amount of detail, I was able to find [two duplicates with a similar problem](https://stackoverflow.com/q/26737366/9374673). Here's [the second one](https://stackoverflow.com/q/7217405/9374673). A simple google of the error text and `pycharm turtle` yielded the answer in this case. – Mihai Chelaru Apr 20 '20 at 19:14

1 Answers1

0

I've tried on my mac and it crashed a few times, I guess the error was on the last line:

input('Press enter to exit')

To make it exit without crashing, add this line at the end and comment out the input().

wn.exitonclick()

I totally understand when it doesn't give you or show any errors on screen, just make sure to add additional comments about what have imported or tried, etc. Hope it helps!

Serg
  • 143
  • 2
  • 8
  • 1
    Oh yes, using the expression wn.exitonclick() works for me! At least I can run the program now as I want even if I still want to understand what the problem is. Thanks – Tricky Devil Apr 20 '20 at 18:32
  • 1
    I'm glad the additional code was useful for you Sebastian! Don't forget to vote on my answer or make further remarks. – Serg Apr 20 '20 at 20:22