是否可以改变turtle中可拖动的poly的pensize?

问题描述 投票:0回答:1

我想改变turtle中可拖动的poly的大小,使poly周围有一个宽阔的边框?

下面是部分代码。

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()

谁能告诉我是怎么做的?

drag-and-drop share turtle-graphics poly
1个回答
1
投票

是否可以改变海龟中可拖动的多边形的大小,使多边形周围有一个宽边框?

是的,可以。不是在多边形创建或注册时,而是通过 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()

这就是 对所举问题的回答,因为复合龟的形式很多,不能拖泥带水。 但这是一件有用的事情。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.