1

This is extremely annoying and I don't know why it's happening. Here's the code:

import pygame
from sys import exit

def createWin(x, y):
    winCreate = True
    while winCreate:
        win = pygame.display.set_mode((x, y))
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

createWin(1000, 1000)

I get this error:

NameError: name 'event' is not defined
2
  • 3
    The error is exactly what it says. The variable event is nowhere defined. I think you should look at the tutorial again and find where the event variable is defined. I am sure pygame has some good tutorials Commented Oct 30, 2019 at 20:08
  • event isn't defined. It's not a primitive in python. I'm assuming that you are looking at a tutorial somewhere where event is being used. Check that tutorial for where they define event, i.e. event = ..., or from X import event Commented Oct 30, 2019 at 20:09

1 Answer 1

5

You should do -

for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        exit()

Otherwise python will not recognize event!

Sign up to request clarification or add additional context in comments.

1 Comment

is possible to wrap this loop inside a function and return the variable event?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.