如何使用SimpleGUIS2Pygame加载图片?

2024-09-30 20:28:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我遵循Coursera课程“An Introduction to Interactive Programming in Python”。在

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

现在,我想用这个函数加载图片:^{}。但错误是:在第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()

非常感谢你的帮助!在


Tags: imagean错误framepygame课程handlercanvas
1条回答
网友
1楼 · 发布于 2024-09-30 20:28:25
  • 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

选择与您的操作系统和Python版本相对应的32位或64位。在

更新

我添加了一个小脚本来检查Pygame的安装: script/游戏机_检查.py在

相关问题 更多 >