How to fix “attribute error” when using pygame [closed]

ε祈祈猫儿з 提交于 2021-01-07 02:55:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!