我正在尝试更改海龟中可拖动多边形的 pensize,以便多边形周围有一个宽边框?
以下是部分代码:
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()
有人可以告诉我它是如何完成的吗?