In python _tkinter.TclError: invalid command name “.!canvas” we face this error message when we type an incorrect turtle.done() or related argument in starting then the python interpreter shows this error message, If you want to fix this error you need to just remove turtle.done() or related argument and type end of your code, For more clarification, see the below example.
Wrong Code
import turtle
t = turtle.Turtle()
turtle.done()
# set the turtle's pen size
t.pensize(3)
# set the number of steps for the loop
steps = 20
# initialize a variable to keep track of the current step
current_step = 0
# move the turtle forward and leave a mark
t.pendown()
while current_step < steps:
t.forward(5)
t.penup()
t.forward(5)
current_step += 1
Error Massage
Traceback (most recent call last):
File "/home/kali/python/webproject/error/main.py", line 41, in <module>
t.pensize(3)
File "/usr/lib/python3.10/turtle.py", line 2092, in pensize
self.pen(pensize=width)
File "/usr/lib/python3.10/turtle.py", line 2425, in pen
self._newLine()
File "/usr/lib/python3.10/turtle.py", line 3292, in _newLine
self.screen._drawline(self.currentLineItem, top=True)
File "/usr/lib/python3.10/turtle.py", line 550, in _drawline
self.cv.tag_raise(lineitem)
File "<string>", line 1, in tag_raise
File "/usr/lib/python3.10/tkinter/__init__.py", line 2971, in tag_raise
self.tk.call((self._w, 'raise') + args)
_tkinter.TclError: invalid command name ".!canvas"
Wrong code line
1 import turtle
2 t = turtle.Turtle()
3 turtle.done()
Correct code line
57 turtle.done()
- Improper action: starting turtle.done().
- Correct action: end of the code.
Entire Correct Code line
mport turtle
t = turtle.Turtle()
# set the turtle's pen size
t.pensize(3)
# set the number of steps for the loop
steps = 20
# initialize a variable to keep track of the current step
current_step = 0
# move the turtle forward and leave a mark
t.pendown()
while current_step < steps:
t.forward(5)
t.penup()
t.forward(5)
current_step += 1
turtle.done()
What is _tkinter.TclError: invalid command name “.!canvas”?
In python _tkinter.TclError: invalid command name “.!canvas” we face this error message when we type an incorrect turtle.done() or related argument in starting then the python interpreter shows this error message.
How to fix turtle.TurtleGraphicsError: There is no shape named Turtle?
If you want to fix this error you need to just remove turtle.done() or related argument and type the end of your code For more clarification, see the above example.
- Another article for you:
Python Unicode error. - Python pygame error.
For more information Visit YouTube Channel.
