I believe the issue your having is when the code throws an exception, pygame.quit() is never called ( in idle) so the window persists. A good way to deal with this is to wrap the execution in a try/except that calls pygame.quit then re raises the exception.
|