如何在Python Turtle中导入图像? [英] How can I import an image in Python Turtle?

查看:1982
本文介绍了如何在Python Turtle中导入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是获取一个图像来替换默认的乌龟,就像在这里完成的一样:

What I want, is to get an image to replace the default turtle, just like it is done here: http://blog.trinket.io/using-images-in-turtle-programs/ .

这是我的代码,但是我不知道为什么它不起作用:

This is my code, but I don't know why it doesn't work:

import turtle

image = "C:/Python27/Pythonprogramming/image.png"
screen = turtle.Screen()

screen.addshape(image)
turtle.shape(image)

turtle.mainloop()

这一切都是为了使乌龟的动作可以通过Python代码进行操纵.我在互联网上进行了搜索,但似乎找不到解决方法.

This is all in effort to make a turtle that's actions can be manipulated through Python code. I have searched all over the internet, but can't seem to find a solution.

在此先感谢您的帮助!

推荐答案

我不确定,但我认为在Windows上,路径将如下所示: "C:\ Python2 \ Pythonprogramming \ image.png" 另外,它究竟会引发什么错误?

I'm not sure but I think on Windows ,the paths will be like this: "C:\Python2\Pythonprogramming\image.png" Also , what error does it raise exactly?

这篇关于如何在Python Turtle中导入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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