4

Although I know I can install ColabTurtle to use Turtle on a Colab Notebook, I cannot figure out how. Could someone please give me an example on how to run Turtle codes on Colab?

1
  • This question is similar to: Using turtle graphics in Google colab. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.
    – ggorlen
    Commented Sep 5 at 17:42

2 Answers 2

6

Here is an example notebook.

First, you need to install it.

!pip install ColabTurtle

Then import all functions and init it.

from ColabTurtle.Turtle import *
initializeTurtle()

Then call normal turtle commands, e.g.

forward(100)
right(90)
forward(100)
right(90)
forward(100)

You can see all supported commands in the code.

0
0

To supplement this excellent answer, if you want to namespace the module to avoid name clashes, you can use

import ColabTurtle.Turtle as t

t.initializeTurtle()
t.forward(30)

Note that the library doesn't implement the same API as Python's built-in turtle module. Run help(t) to see the list of available methods on what appears to be a singleton turtle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.