python AttributeError: module 'pygame' has no attribute 'display'

原问题网址:https://stackoverflow.com/questions/39840580/python-attributeerror-module-pygame-has-no-attribute-display

问题:当一个小哥试图用python中的pygame创建一个窗口时出现了RT问题:

          

>>> import pygame
>>> (width, height) = (300, 200)
>>> screen = pygame.display.set_mode((width, height))

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    screen = pygame.display.set_mode((width, height))
AttributeError: module 'pygame' has no attribute 'display'

问题原因可能有以下几个方面:

1.需要先使用

pygame.init()

2.确保自己的文件等命名中没有使用pygame.py或者pygame关键字

可以通过以下代码查询是否有此类文件:

    import pygame
    print('Path to module:',pygame._file_)

3.可能使用的pygame版本没有这个attribute

   可以通过dir(pygame)函数来查看当前版本中包含哪些attribute




  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值