1

The game freezes instead of quitting. I have to exit from Idle. Any ideas on what to do?

def quit_game():
    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            sys.exit()
quit_game()
pewpew
  • 700
  • 2
  • 9
  • 32
  • Running a file from an Idle editor is intended to be similar to running the file from the command line with `python -i path_to_file.py`. If you run your game with the above code with `python -i` at a command line, does it do the same as you reported (freeze instead of quitting)? – Terry Jan Reedy Apr 26 '15 at 20:31
  • I just had a pygame programmer try the experiment I suggested (with 3.4 on Win 7) and indeed the game window freezes while the command window shown an interactive >>> prompt. – Terry Jan Reedy Apr 26 '15 at 20:55

2 Answers2

0

This is an IDLE bug. I would recommend using a real IDE such as pycharm. However to fix this issue, have a look at the pygame FAQ. They offer this solution:

# ... running = True
while running:
    event = pygame.event.wait ()
    if event.type == pygame.QUIT:
        running = False  # Be IDLE friendly
pygame.quit ()
JamesWat
  • 60
  • 1
  • 8
  • 1
    The fact that Idle catches SystemExit is a design decision, not a bug. It is probably not unique to Idle. It is usually a plus for users, even if not when running PyGame. Perhaps the details of behavior could be tweeked. I think the FAQ is wrong in the speculation about keeping references. I know it is wrong about the claimed difference between starting with 'Edit with Idle' and the Idle Start menu icon. – Terry Jan Reedy Apr 26 '15 at 20:38
  • 1
    The game window freeze behavior is how python itself behaves with -i passed. See my comments to the question. It is not an Idle bug. Idle is a real IDE, even if not as complicated or sophisticated in most way as PyCharm. – Terry Jan Reedy Apr 26 '15 at 20:59
  • Those are good points I wasn't actually aware of, thanks. (However IDLE is surely just a text editor and shell combo? -- irrelevant to the problem however) – JamesWat Apr 27 '15 at 01:29
0

It may work....

def quit_game():
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
    quit_game()
Chhaya Vankhede
  • 316
  • 2
  • 14