以下是我的代码:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.event.quit()
我用的是PyCharm,它突出显示了QUIT
并说Cannot find reference 'QUIT' in '__init__.py'
。这个程序没有像预期的那样工作。你知道吗
编辑:代码如下。KU LEFT或其他键也显示相同的错误
import pygame
def move(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.event.quit()
keys = pygame.key.get_pressed()
for key in keys:
if keys[pygame.K_LEFT]:
self.dirnx = -1
self.dirny = 0
self.turns[self.head.pos[:]] = [self.dirnx, self.dirny]
elif keys[pygame.K_RIGHT]:
self.dirnx = 1
self.dirny = 0
self.turns[self.head.pos[:]] = [self.dirnx, self.dirny]
elif keys[pygame.K_UP]:
self.dirnx = 0
self.dirny = -1
self.turns[self.head.pos[:]] = [self.dirnx, self.dirny]
elif keys[pygame.K_DOWN]:
self.dirnx = 0
self.dirny = 1
self.turns[self.head.pos[:]] = [self.dirnx, self.dirny]
错误:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:/Users/HasanIsgandarli/PycharmProjects/untitled/Snake.py", line 151, in <module>
main()
File "C:/Users/HasanIsgandarli/PycharmProjects/untitled/Snake.py", line 147, in main
s.move()
File "C:/Users/HasanIsgandarli/PycharmProjects/untitled/Snake.py", line 56, in move
pygame.event.quit()
AttributeError: module 'pygame.event' has no attribute 'quit'
Process finished with exit code 1```
把它改成
if event.type == pygame.QUIT: pygame.display.quit() pygame.quit()
相关问题 更多 >
编程相关推荐