AttributeError: 'pygame.Surface' object has no attribute 'event'

前端 未结 1 1390
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 12:16

I am creating my first game in python and was doing it part by part. Than I got this error message:

AttributeError: \'pygame.Surface\' object has no          


        
相关标签:
1条回答
  • 2021-01-24 12:41

    Because the module pygame is shadowed by the variable pygame that refers to the display Surface object. You have to rename the variable that holds the Surface object which is associated to the Pygame display:

    pygame = pygame.display.set_mode([screen_width,screen_width])

    pygame_surf = pygame.display.set_mode([screen_width,screen_width])
    

    Note that when pygame.event.get() is called, pygame is understood as the Surface object pygame and a Surface object does not have an attribute event.

    0 讨论(0)
提交回复
热议问题