Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+6 votes

I was wondering why do I get an error in thonny when I close the window without completing the quiz.
If self.isClosed() : raise GraphicsError("getMouse in closed window")
graphics.GraphicsError: getMouse in closed window

And is there a way to get rid of this error?

asked in CSC201 Spring 2021 by (1 point)

3 Answers

+4 votes
 
Best answer

Indeed, it's possible for you to handle errors that come up when executing Python code by using the try: ... except ... language feature.

At the bottom of quiz.py, instead of just calling main(), put this:

try:
    main()
except GraphicsError as error:
    print("Ignoring: ", error)
    print("Goodbye.")

Indented in between try and except you put some code that might cause an error. After except you put the name of the error you want to "handle", then as and then a variable name that will store the error object that describes the error that happened. Indented after the except statement, put the code you want to run when the error happens (instead of having the program immediately DIE with a red error message!). If you don't want to print or do anything, you could put pass there, although it's usually better to do something, so you at least know that an error happened...

answered by (508 points)
+6 votes

You should finish answering the questions then when you close the window the error won't show up.

answered by (1 point)
+3

Yes thats what I did
But I was just curious if someone doesnt want to play the whole game and quits and they see that error it would be weird

+5 votes

You should use the Stop button instead of closing the window.

answered by (1 point)
...