K
K
Kapsamun Artem2021-11-21 21:31:05
Python
Kapsamun Artem, 2021-11-21 21:31:05

Invalid command name ".!canvas" in turtle. How to decide?

When I want to close the turtle application, I get an error:

Mistake

Traceback (most recent call last):
  File "C:\Users\Artem\Desktop\програмирование\python\6\tree.py", line 36, in <module>
    leo.left(60)
  File "C:\Users\Artem\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1700, in left
    self._rotate(angle)
  File "C:\Users\Artem\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 3279, in _rotate
    self._update()
  File "C:\Users\Artem\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 2661, in _update
    self._update_data()
  File "C:\Users\Artem\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 2651, in _update_data
    self.screen._drawline(self.currentLineItem, self.currentLine,
  File "C:\Users\Artem\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 544, in _drawline
    self.cv.coords(lineitem, *cl)
  File "<string>", line 1, in coords
  File "C:\Users\Artem\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2795, in coords
    self.tk.call((self._w, 'coords') + args))]
_tkinter.TclError: invalid command name ".!canvas"


The code:
The code

import turtle


WIDTH, HEIGHT = 1600, 900
screen = turtle.Screen()
screen.setup(WIDTH, HEIGHT)
screen.screensize(3 * WIDTH, 3 * HEIGHT)
screen.bgcolor('black')
screen.delay(0)
leo = turtle.Turtle()
leo.pensize(3)
leo.speed(0)
leo.color('orange')

gens = 20
axiom = 'A'
chr_1, rule_1 = 'A', 'AB'
chr_2, rule_2 = 'b', 'A'
step = 50
angle = 60

def apply_rules(axiom):
  return ''.join([rule_1 if chr == chr_1 else rule_2 for chr in axiom])

for gen in range(gens):
  turtle.pencolor('white')
  turtle.goto(-WIDTH // 2 + 60, -HEIGHT // 2 + 60)
  turtle.clear()
  turtle.write(f'generation: {gen}', font=('Arial', 60, 'normal'))
  leo.setheading(0)
  leo.goto(0, 0)
  leo.clear()

  for chr in axiom:
    if chr == chr_1:
      leo.left(60)
      leo.forward(step)
    elif chr == chr_2:
      leo.right(60)
      leo.forward(step)
  axiom = apply_rules(axiom)

screen.exitonclick()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
exxxt4zy, 2021-11-22
@exxxt4zy

It says that there is no such command. You need to look at the library, documentation, see

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question