【问题标题】:Python Turtle stamp same shape/image at different positionsPython Turtle 在不同位置标记相同的形状/图像
【发布时间】:2020-12-01 20:17:51
【问题描述】:

我试图在画布上的多个位置标记相同的形状(我添加到海龟的图像)。但是,似乎每次我印第二个形状时,第一个就消失了。

有没有办法使用相同的形状/图像在画布上显示多个图章?使用海龟中已有的形状时,这似乎不是问题。

【问题讨论】:

    标签: python turtle-graphics python-turtle


    【解决方案1】:

    在您要求他们这样做之前,您应该能够在同一图像的任意数量的副本上加盖印章而不会消失。对于自定义多边形形状:

    from turtle import Screen, Shape, Turtle
    
    POLYGON = (
        (10, 10),
        (0, 10),
        (-10, 0),
        (0, -10),
        (10, -10),
    )
    
    screen = Screen()
    
    screen.register_shape('house', Shape('polygon', POLYGON))
    
    turtle = Turtle('house')
    turtle.penup()
    
    for x in range(-200, 200, 30):
        turtle.setx(x)
        turtle.stamp()
    
    turtle.hideturtle()
    screen.exitonclick()
    

    或者对于自定义图像形状:

    from turtle import Screen, Turtle
    
    IMAGE = "home-5-24.gif"  # https://www.iconsdb.com/gray-icons/home-5-icon.html
    
    screen = Screen()
    
    screen.register_shape(IMAGE)
    
    turtle = Turtle(IMAGE)
    turtle.penup()
    
    for x in range(-200, 200, 30):
        turtle.setx(x)
        turtle.stamp()
    
    turtle.hideturtle()
    screen.exitonclick()
    

    【讨论】:

      猜你喜欢
      • 2021-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      相关资源
      最近更新 更多