海龟屏幕。跟踪器(0)不会停止所有动画

2024-05-20 08:01:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我认为使用Screen.tracer(0)可以禁用Python海龟图形中的动画。然而,在下面的程序中,如果您注释掉screen.update(),仍然会出现一些动画-绘制海龟轨迹,尽管海龟不会“移动”(或更新)。请问这里发生了什么事?有没有办法使屏幕更新完全手动

import turtle

def move():
    my_turtle.forward(1)
    my_turtle.right(1)
    screen.update()  # Comment out this line to see issue.
    screen.ontimer(move, 10)

screen = turtle.Screen()
my_turtle = turtle.Turtle()
my_turtle.shape("turtle")
screen.tracer(0)
move()
turtle.done()

Tags: 程序图形move屏幕my轨迹绘制update
2条回答

不,屏幕。跟踪器(0)不会停止所有动画。一些turtle命令,如end_fill()直接调用screen.update(),另一些命令,如dot()由于它们依次调用的其他方法而调用它。您仅在调用update()时通知系统,而不是完全控制它

把你的update()调用放在你认为需要的地方,不要假设某些方法会强制更新,否则海龟的未来更新可能会破坏你的代码。(也就是说,可能有人真的在修理乌龟。)

有关可能有用的详细信息,请参阅my^{} rules of thumb和有关first argument's numeric value的信息

在tutle.py中,forward()调用设置端点的_go(),然后调用_goto()

_goto()如果线段超过42,则创建一条新线

if len(self.currentLine) > 42: # 42! answer to the ultimate question
                               # of life, the universe and everything
    self._newLine()

该值似乎是任意的;您可以将其设置为更高的值,但是会出现暂停,似乎什么都没有发生

def _newLine(self, usePos=True):
    """Closes current line item and starts a new one.
       Remark: if current line became too long, animation
       performance (via _drawline) slowed down considerably.
    """

相关问题 更多 >