微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我在 vscode 中使用 pygame 而在 pycharm 中没有出现错误?

如何解决为什么我在 vscode 中使用 pygame 而在 pycharm 中没有出现错误?

所以这正是我在 vs 代码中写的

import pygame


WIDTH,HEIGHT = 600,500

WIN = pygame.display.set_mode((WIDTH,HEIGHT))

running = True

while running:
 for event in pygame.event.get():
  if event.type == pygame.QUIT:
   running = False
   

我收到错误模块“pygame”没有“退出”成员 if 语句有错误

   if event.type == pygame.QUIT:

它的 pygame.QUIT

解决方法

原因:出于安全原因,Pylint 默认只信任标准库 stdlib 中的 C 扩展,但模块“pygame”并不来自它。

请在 settings.json 中添加以下设置以将其添加到白名单:

"python.linting.pylintArgs": ["--extension-pkg-whitelist=pygame"],

enter image description here

或使用以下设置:

 "python.linting.pylintArgs": [ "--errors-only","--generated-members=pygame.* " ]

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。