4

I have some Pygame code that is working fine up until I try to close the program. The program keeps telling me that sys is not defined. I am using the more python programming for the absolute beginner to get the hang of Pygame.

import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((600,500))

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()

My expected result is that the window will close but instead the window stays open and this error is spat out: NameError: name 'sys' is not defined

Micah Lehman
  • 81
  • 1
  • 1
  • 8

1 Answers1

10

sys is a module that you need to import, preferably at the beginning.

import sys
Alex Hall
  • 34,833
  • 5
  • 57
  • 89