如何使用SimpleGUIS2Pygame加载图片?
How to use SimpleGUIS2Pygame load picture?
我学习了 Coursera 课程“An Introduction to Interactive Programming in Python”。
我试着在自己的电脑上练习一些东西。我找到了包“SimpleGUICS2Pygame" which can replace the simplegui
of CodeSkulptor.
现在,我想用这个函数加载一张图片:load_image()
。但是错误说:在第 6 行:"AssertionError: Pygame not available!"
所以我必须从 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()
非常感谢您的帮助!
import pygame FAILED! No module named pygame
表示 Pygame 未 安装此版本的 Python。
import pygame FAILED! DLL load failed
可能意味着您为这个版本的 Python 安装了错误的 Pygame 版本。
这里是 Pygame 的几个版本:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
选择与您的 OS 和您的 Python 版本相对应的正确选项,32 位或 64 位。
更新
我添加了一个小脚本来单独检查 Pygame 安装:
script/pygame_check.py
我学习了 Coursera 课程“An Introduction to Interactive Programming in Python”。
我试着在自己的电脑上练习一些东西。我找到了包“SimpleGUICS2Pygame" which can replace the simplegui
of CodeSkulptor.
现在,我想用这个函数加载一张图片:load_image()
。但是错误说:在第 6 行:"AssertionError: Pygame not available!"
所以我必须从 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()
非常感谢您的帮助!
import pygame FAILED! No module named pygame
表示 Pygame 未 安装此版本的 Python。import pygame FAILED! DLL load failed
可能意味着您为这个版本的 Python 安装了错误的 Pygame 版本。
这里是 Pygame 的几个版本: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
选择与您的 OS 和您的 Python 版本相对应的正确选项,32 位或 64 位。
更新
我添加了一个小脚本来单独检查 Pygame 安装: script/pygame_check.py