AttributeError: module 'ColabTurtle.Turtle' has no attribute 'undo'
Asked Answered
M

1

1

while using th epython library turtle i am getting the error

"error"

AttributeError module ColabTurtle.Turtle has no attribute undo

"code"

import ColabTurtle.Turtle as t
t.initializeTurtle(initial_speed=5)
t.speed(1)
t.forward(100)
t.undo()
Moravian answered 7/6, 2021 at 4:51 Comment(1)
Related: Google Colaboratory: AttributeError: module 'ColabTurtle.Turtle' has no attribute 'circle'. It's a different API than Python's built in turtle.Justifier
T
0

You're using a stripped down version of Turtle, that doesn't include an undo buffer.
https://github.com/tolgaatam/ColabTurtle/blob/master/ColabTurtle/Turtle.py

You'd have to roll your own undo function that parses global svg_lines_string and removes the last entry. Not about to test that, but it would be something like this:

def undo():
    global svg_lines_string
    last_entry  = t .svg_lines_string .rfind('<line x1=')
    t .svg_lines_string  = t .svg_lines_string[ :last_entry ]
    t ._updateDrawing()

undo()


Alternatively, you could use t.clear() and then redraw everything up to that point, exluding your last step.



If it supports multiple turtles on the screen at once, then you could use a secondary turtle that only draws those commands you wish to discard. This way, when you do a t2.clear(), it won't erase your original turtle.

Terminology answered 7/6, 2021 at 5:39 Comment(2)
The above code which you gave dosent work. But yes using t.clear() and then t.home() together worked. Using the above code gives some unexpected output. It gives the output in such a way 1>>>>first it forms a line and then delete the line and then creates the new 2nd line and some another position not at the same position as of the first line and then dosen't delets that but i think clearing the first line is ok but it should not creates a new line on the output window.Moravian
oh yea yea, you want to discard the last entry instead of keep it. so it should be [ :last_entry ]Terminology

© 2022 - 2024 — McMap. All rights reserved.