gpt4 book ai didi

python - 无法添加形状(图片)

转载 作者:行者123 更新时间:2023-11-28 18:38:07 25 4
gpt4 key购买 nike

我正在尝试将图像添加到我的代码中,但它不断引发错误

Bad arguments for register_shape

我正在学习 http://blog.trinket.io/using-images-in-turtle-programs/ 上的教程

我的代码是:

import turtle

screen = turtle.Screen()

# click the image icon in the top right of the code window to see
# which images are available in this trinket
image = "C:\...\rocketship.png"

# add the shape first then set the turtle shape
screen.addshape(image)
turtle.shape(image)

我正在使用 python 2.6。此外,当我使用

的功能时

screen.bgpic("C:...\Backgrounds\giphy2.gif")

背景有效。

最佳答案

您可以在这里寻找答案: How can i add an image (Python)

The turtle module does have support for images, but only GIF images, not PNG or any other format. As the docs for addshape say:

name is the name of a gif-file and shape is None: Install the corresponding image shape.

关于python - 无法添加形状(图片),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30426500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com