如何修复命名空间Pygame事件错误?



Python和Pygame新手。我在一些教程中看到,如果你使用from pygame import *,你可以在调用方法等时不再使用pygame.<whatever>。然而,对于事件,它似乎抛出错误AttributeError: 'Event' object has no attribute 'get'。我该如何解决这个问题?下面是我的代码:

from pygame import*
#import pygame
import random
WIDTH = 500
HEIGHT = 500
FPS = 30
#Window initialization
init()
mixer.init() #used for sounds
screen = display.set_mode((WIDTH, HEIGHT))
display.set_caption("Test Game")
clock = time.Clock()
#Main game loop
running = True
while running:
clock.tick(FPS) #sets game frame rate
#Handle events
for event in event.get():
if event.type == QUIT:
running = False
#Draw Here
draw.circle(screen, (255, 0, 0), (200, 200), 40)

#Render drawing to screen
display.flip()
quit()

event重命名为e:

for e in event.get():
if e.type == QUIT:

最新更新