是否可以更改海龟中可拖动多边形的大小?

Is it possible to change the pensize of a drag-able poly in turtle?

我正在尝试更改 turtle 中可拖动多边形的笔大小,以便多边形周围有一个宽边框?

部分代码如下:

from turtle import Turtle,Shape,Screen

def simple_polygon(turtle):

    shape = Shape("compound")
    turtle.begin_poly()
    turtle.circle(50)
    shape.addcomponent(turtle.get_poly(), "yellow", "green")  # component #2
    screen.register_shape("simple_polygon", shape)
    turtle.reset()


def drag_handler(turtle, x, y):
    turtle.ondrag(None)  # disable ondrag event inside drag_handler
    turtle.goto(x, y)
    turtle.ondrag(lambda x, y, turtle=turtle: drag_handler(turtle, x, y))

screen = Screen()

magic_marker = Turtle()
simple_polygon(magic_marker)
magic_marker.hideturtle()

mostly_green = Turtle(shape="simple_polygon")
mostly_green.penup()
mostly_green.goto(150, 150)
mostly_green.ondrag(lambda x, y: drag_handler(red, x, y))

screen.mainloop()

有人可以告诉我怎么做吗?

Is it possible to change the pensize of a drag-able poly in turtle, so that the poly would have a broad border around it?

是的。不是在多边形创建或注册时,而是通过 outline 参数到 shapesize()(又名 turtlesize()),一旦它被设置为海龟光标:

from turtle import Screen, Turtle

def drag_handler(x, y):
    turtle.ondrag(None)  # disable event inside handler
    turtle.goto(x, y)
    turtle.ondrag(drag_handler)

screen = Screen()

turtle = Turtle()
turtle.begin_poly()
turtle.circle(50)
turtle.end_poly()
screen.register_shape('simple_polygon', turtle.get_poly())
turtle.reset()

turtle.shape('simple_polygon')
turtle.color('green', 'yellow')
turtle.shapesize(outline=25)
turtle.penup()

turtle.ondrag(drag_handler)

screen.mainloop()

不是所引用问题的答案,因为复合海龟有多种形式,并且不可拖动。但却是一件有用的事情: