AttributeError:'事件'对象没有属性' get'

时间:2017-09-03 14:28:31

标签: python python-2.7 pygame

我正在尝试在python 2.7.5中运行以下程序

import pygame ,sys
pygame.init()
pygame_events = pygame.event.get()
screen = pygame.display.set_mode([640, 480]) 
screen.fill([255,255,255])
pygame.draw.circle(screen, [255, 0, 0],[100, 100], 30 ,0)
pygame.display.flip()
running = True
while running:
    for event in pygame.event.get():
        if event.get == pygame.QUIT:
            running = False
pygame.quit()

但是,它不起作用,我收到以下错误消息

Traceback (most recent call last):
File "C:\Python27\tanks\tanks_progam.py", line 10, in <module>
if event.get == pygame.QUIT:
AttributeError: 'Event' object has no attribute 'get'

有人可以帮我解决问题吗?

1 个答案:

答案 0 :(得分:1)

应该是type而不是get

if event.type == pygame.QUIT: