为什么我在 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