Reputation: 11
I am creating my first game in python and was doing it part by part. Than I got this error message:
AttributeError: 'pygame.Surface' object has no attribute 'event'
My code:
import pygame
pygame.init()
screen_width = 800
screen_height = 600
pygame = pygame.display.set_mode([screen_width,screen_width])
gameover = False
while not gameover:
for event in pygame.event.get():
print(event)
Upvotes: 1
Views: 417
Reputation: 211277
Because the module pygame
is shadowed by the variable pygame
that refers to the display Surface object. You have to rename the variable that holds the Surface object which is associated to the Pygame display:
pygame = pygame.display.set_mode([screen_width,screen_width])
pygame_surf = pygame.display.set_mode([screen_width,screen_width])
Note that when pygame.event.get()
is called, pygame
is understood as the Surface object pygame
and a Surface object does not have an attribute event
.
Upvotes: 1