0

我学习 Coursera 课程“ Python 交互式编程简介”。

我尝试在自己的电脑上练习一些东西。我找到了可以替换CodeSkulptor的包“ SimpleGUICS2Pygame ” 。simplegui

现在,我想用这个功能加载一张图片:load_image(). 但是错误说:在第 6 行:“AssertionError:Pygame 不可用!”

所以我必须从Pygame网站安装 pygame。但它仍然是同样的错误。我不知道,为什么 pygame 不可用。(我使用 Windows 8.1)。以下是我的代码,它是来自 codeskulptor 的示例:

import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

def draw_handler(canvas):
    canvas.draw_image(image, (1521 / 2, 1818 / 2), (1521, 1818), (50, 50), (100, 100))

image = simplegui.load_image('http://commondatastorage.googleapis.com/codeskulptor-assets/gutenberg.jpg')

frame = simplegui.create_frame('Testing', 100, 100)
frame.set_draw_handler(draw_handler)
frame.start()

非常感谢您的帮助!

4

1 回答 1

1
  • import pygame FAILED! No module named pygame表示没有为此版本的 Python 安装 Pygame。
  • import pygame FAILED! DLL load failed可能意味着您为此版本的 Python 安装了错误版本的 Pygame。

这是 Pygame 的几个版本: http ://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

选择与您的操作系统和 Python 版本(32 位或 64 位)相对应的正确选项。

更新

我添加了一个小脚本来单独检查 Pygame 安装: script/ pygame_check.py

于 2015-10-16T11:44:09.903 回答