导入“ pygame”无法解决

发布于 2025-01-18 05:56:06 字数 397 浏览 2 评论 0原文

我在命令提示符下使用 pip 安装了 pygame,但它仍然显示错误。我已经尝试更改路径,以便可以正确访问 pip 并使用“pygame.init()”行,但错误仍然出现。

这是代码:


import pygame, sys

pygame.init()

w, h = 600, 600
r = (255, 0, 0)

s = pygame.display.set_mode( (w, h) )
s.fill(r)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    pygame.display.update()

I installed pygame using the pip in command prompt but it still shows an error. I have already attempted changing the path so pip could properly be accessed and using the line "pygame.init()" but the error still appears.

Here's the code:


import pygame, sys

pygame.init()

w, h = 600, 600
r = (255, 0, 0)

s = pygame.display.set_mode( (w, h) )
s.fill(r)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    pygame.display.update()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2025-01-25 05:56:06

顺便说一句,如果它仍然不起作用,您可以尝试使用 Pycharm。如果你做不到,你可以尝试使用 replit 并下载 pygame 包,然后使用 Github 导出它。

by the way if it still isn't working you could try using Pycharm. If you can't do that you could try using replit and downloading the pygame package, then exporting it with Github.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文