问题
I got an error while using pygame library:
Module 'pygame' has no 'QUIT' member
Module 'pygame' has no attribute 'init'
this is my code
import pygame
#initialize pygame
pygame.init()
#create the game screen
screen = pygame.display.set_mode((800,600))
# title and icon
pygame.display.set_caption("space invaders")
# game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.quit:
running = False
回答1:
Python is case sensitive. It has to be QUIT rathe rather than quit:
if event.type == pygame.quit:
if event.type == pygame.QUIT:
Note pygame.quit() is a function that uninitialize all pygame modules, but pygame.QUIT is the enumeration constant for the QUIT event (see pygame.event).
来源:https://stackoverflow.com/questions/65265219/how-to-fix-attribute-error-when-using-pygame