2013-08-22 92 views
-1

我是比較新的蟒蛇,我一直有一個去搞亂髓pygame的..對我來說,這個代碼看起來不錯:AttributeError的:「詮釋」對象有沒有屬性「KEYDOWN」

import pygame 

class Game(object): 
    def main(self, screen): 
     image = pygame.image.load("images\player.png") 
     while 1: 
      for event in pygame.event.get(): 
       if event.type == pygame.QUIT: 
        running = false 
       if event.type.KEYDOWN and event.key == pygame.K.ESCAPE: 
        running = false 

      screen.fill((200,200,200)) 
      screen.blit(image, (320, 240)) 
      pygame.display.flip() 

if __name__ == "__main__": 
    pygame.init() 
    screen=pygame.display.set_mode((640,480)) 
    Game().main(screen) 

然而,當我運行它,我得到這個錯誤:

File "C:\Users\jwquick\Documents\Programming\Python\Pygame Test\main.py", line 
10, in main 
    if event.type.KEYDOWN and event.key == pygame.K.ESCAPE: 
AttributeError: 'int' object has no attribute 'KEYDOWN' 

回答

0

嘗試:

if event.type==KEYDOWN and event.key == pygame.K.ESCAPE:

1
from pygame.locals import * 

# ... 

for event in pygame.event.get(): 
    if event.type == KEYDOWN: 
     if event.key == K_ESCAPE: 
      print("Quit") 
相關問題