无法导入任何 pygame 函数 (E1101) [英] Can't import any pygame functions (E1101)

查看:36
本文介绍了无法导入任何 pygame 函数 (E1101)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下代码时,出现白屏,然后快速消失.我使用 pip3 在 VSCode 终端上安装了 pygame(我在 mac 上),现在我终于让它导入 pygame,对于每个名为clock"或pygame.KEYDOWN"的函数,我都会遇到多个错误.他们说模块‘pygame’没有‘KEYDOWN’成员"[E1101].init"成员也出现错误.

When I run the following code, a white screen appears and then quickly disappears. I installed pygame on the VSCode terminal with pip3 (I am on mac) and now that I finally got it to import pygame, I get multiple errors for every function called such as "clock" or "pygame.KEYDOWN". They say "Module 'pygame' has no 'KEYDOWN' member" [E1101]. I also get an error with the "init" member.

我看到其他帖子告诉我将某些内容复制并粘贴到 json 设置中,但是当我尝试这样做时,我遇到了更多错误.

I've seen other posts that tell me to copy and paste something into the json settings, but when I tried that I got even more errors.

#Game

#By Robert Smith

#Initialize python
import pygame
pygame.init()

#Set the screen
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255,255,255))
background = background.convert()
screen.blit(background, (0 , 0))

#Make the window exitable
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        mainloop == False #close the window
    elif event.type == pygame.KEYDOWN:
        if event.key == pygame.K_ESCAPE:
            mainloop = False

#Set the framerate
milliseconds = clock.tick(60)#DO NOT GO FASTER THAN THIS FRAMERATE

推荐答案

试试这个:

keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
    mainloop == False #close the window
elif event.type == keys[pygame.K_DOWN]:
    if event.key == keys[pygame.K_ESCAPE]:
        mainloop = False

还有这个:

milliseconds = pygame.time.Clock.tick(60)

这篇关于无法导入任何 pygame 函数 (E1101)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆