f._weiss
f._weiss

Reputation: 43

NameError: name 'quit' is not defined for pygame

I tried to make a little snake game (with pygame) and I tried to export it as a .exe with cx_Freeze. The game works fine, until I close the window. When I do that, there is this Error message:

Error message

But I just used it to close the game loop:

for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        quit()
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_ESCAPE:
            pygame.quit()
            quit()
        if event.key == pygame.K_SPACE:
            Game()

If I open the .py file I don't get any Error message. I don't have any Idea how I possibly could fix this problem.

My setup.py:

import cx_Freeze

executables = [cx_Freeze.Executable("snake.py", base="Win32GUI", icon="links/icon.ico")]

cx_Freeze.setup(
    name="Snake",
    options={"build_exe": {"packages": ["pygame"], "include_files": ["links/"]}},
    executables=executables
    )

And here is my Code: Codeshare.io

Upvotes: 1

Views: 2189

Answers (1)

f._weiss
f._weiss

Reputation: 43

So I solved the problem by typing sys.exit() instead of typing quit() I tried this before but I didn't know that I had to import sys.

(Sorry I'm a beginner)

Upvotes: 2

Related Questions