简体   繁体   English

_tkinter.TclError:无效的命令名称“.!canvas”在海龟图形中的错误

[英]_tkinter.TclError: invalid command name ".!canvas" error in turtle grahics

I'm trying to create a polygon using turtle graphics but I keep on running to this error我正在尝试使用海龟图形创建多边形,但我一直遇到此错误

self.tk.call((self._w, 'coords') + args))] _tkinter.TclError: invalid command name ".!canvas self.tk.call((self._w, 'coords') + args))] _tkinter.TclError:无效的命令名称“.!canvas

"

import turtle
bob = turtle.Turtle()
def polygon(t,length,n):
    angle = 360%n
    for i in range(n):
        t.fd(length)
        t.lt(angle)

polygon(bob,70,7)

I can't reproduce your error, we may need to see more of it to understand the problem.我无法重现您的错误,我们可能需要查看更多信息才能了解问题所在。 However, code-wise, I would have expected / (floating division) instead of % (modulus remainder):但是,在代码方面,我会期望/ (浮动除法)而不是% (模余数):

import turtle

def polygon(t, length, n):
    angle = 360 / n

    for _ in range(n):
        t.forward(length)
        t.left(angle)

bob = turtle.Turtle()
polygon(bob, 70, 7)

turtle.done()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM