我这没有key属性应该怎么办
前面是这样输入的:elif event.key.type == pygame.KEYDOWN:
if event.key == 273 or event.key == 119:
direct = 'up'
elif event.key == 274 or event.key == 115:
direct = 'down'
elif event.key == 275 or event.key == 100:
direct = 'right'
elif event.key == 276 or event.key == 97:
direct = 'left'
报错就是这样的:
Traceback (most recent call last):
File "C:\Users\亦尘\Desktop\python\贪吃蛇.py", line 48, in <module>
elif event.key.type == pygame.KEYDOWN:
AttributeError: 'Event' object has no attribute 'key'
而我的pygame是pip************下载的,就是昨天在B站上一直找才找到我能看懂的下载教程 贴全代码。
参考一下下面代码
>>> print = 1
>>> print('abc')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
print('abc')
TypeError: 'int' object is not callable ba21 发表于 2021-7-8 22:13
贴全代码。
参考一下下面代码
pygame 2.0.1 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\亦尘\Desktop\python\贪吃蛇.py", line 48, in <module>
elif event.key.type == pygame.KEYDOWN:
AttributeError: 'Event' object has no attribute 'key'
这样吗? Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\亦尘\Desktop\python\贪吃蛇.py ==================
pygame 2.0.1 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\亦尘\Desktop\python\贪吃蛇.py", line 48, in <module>
elif event.key.type == pygame.KEYDOWN:
AttributeError: 'Event' object has no attribute 'key'
>>>
全部粘贴过来了
看下这边函数完整的代码
这个要给完整的代码才能分析,如果你不想看到这个报错就用get去获取,如果要解决你没有key属性就得给完整代码哦
页:
[1]