AttributeError: module 'pygame' has no attribute 'dispaly'
时间: 2023-11-13 09:04:34 浏览: 47
这个错误通常是因为拼写错误或者是导入模块的方式不正确导致的。正确的属性名称应该是"display"而不是"dispaly"。请检查你的代码中是否有这样的拼写错误。此外,确保你正确地导入了pygame模块。你可以使用以下代码来测试pygame模块是否正确导入:
```
import pygame
print('Path to module:', pygame._file_)
```
如果你看到了pygame模块的路径,那么你已经成功导入了pygame模块。如果你仍然遇到问题,请检查你的安装是否正确或者尝试重新安装pygame模块。
相关问题
AttributeError: module 'pygame.display' has no attribute 'filp'
AttributeError: module 'pygame.display' has no attribute 'filp'是一个常见的错误,它表示在pygame.display模块中不存在名为'filp'的属性。根据引用,您提供了一个链接,它可能包含了关于解决此问题的更多信息。根据引用,您提供了一个代码片段,其中显示了一个类似的错误,但是错误是关于pygame.display模块中的'display'属性。根据这些信息,我们可以得出结论,您可能会遇到不同版本的pygame库或不正确的模块导入。请确保您已正确安装pygame库,并使用正确的模块导入语句。如果问题仍然存在,请检查您的代码中是否有拼写错误或其他语法错误。如果您需要更具体的解决方法,请提供更多的代码和错误信息。
AttributeError: module 'pygame' has no attribute 'K_Q'
这个错误通常是因为在使用 Pygame 模块时,将按键为 `K_Q` 的键盘事件写成了 `pygame.K_Q`,导致程序无法识别该按键。
解决方法是将 `pygame.K_Q` 改为 `pygame.K_q`,即将大写的 Q 改为小写的 q。这是因为在 Pygame 中,所有的按键都是小写字母。
你可以参考下面的代码修改:
```python
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
pygame.quit()
exit()
```
这样就可以避免 `AttributeError: module 'pygame' has no attribute 'K_Q'` 这个错误了。
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)