To test my pygame program, I wanted to make a green rectangle move using keyboard inputs, but when I run it, it crashes with: AttributeError: module 'pygame' has no attribute 'event_get'
Here's the code:
player_x = 50
player_y = 50
display.fill(white)
pygame.draw.rect(display,green,(player_x,player_y,75,100))
pygame.display.update()
run = True
while run:
for event in pygame.event_get():
if(event.type == pygame.KEYDOWN):
if(event.key == pygame.K_RIGHT):
player_x += 10
screen.blit((player_x, payer_y))
pygame.display.update()
#Exit game
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.flip()
clock.tick(60)
You just write it wrong change from pygame.event_get() to pygame.event.get()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.