- Summary of gotchas and analysis
- Just installing it is hard:
turtle.mainloop,turtle.exitonclickorturtle.donein the wrong spot (or forgetting to use them at all, or thinkingexitonclickis a normal click handler).- Too many aliases for every function call, breaking the Zen of Python and introducing confusion.
- Poorly-named legacy Logo methods like
puandseth(although useful for those with limited typing skills). Doesturtle.down()move the turtle downward or put the pen down? - Weird function names like
tracer. done()doesn't exit turtle, it actually starts the main (infinite) loop, leading to confusion.- Confusion between procedural and OOP APIs.
- "Ghost" turtles:
- Gotchas subclassing turtle:
- Paddles on my Pong game do not move after pressing the keys on Python 3.11 Turtle Graphics
- How can I solve the key error in this POO turtle game? (also typoing
__init__as__int__) - Ping Pong Game Class Inheritance confusion
- AttributeError: 'Paddle' object has no attribute 'screen'. Did you mean: '_screen'? and Turtle Subclass "object has no attribute '_shown'" (forgot to call the super class init)
- Forgetting to call
Screen().listen()to enable key handlers. - Calling key handlers immediately:
- No clear path to writing a decent real-time rendering loop or handling multiple keypresses easily ("roll it yourself" basically).
tracer(0)/turtle.update()confusion.- Turtle images don't rotate
- Hard to keep things in bounds of the screen/window.
- Using
while True: turtle.update()to run an event loop rather thanontimer. - Writing unreachable code after infinite
whileloops. and this and this - Registering one-time key listeners repeatedly in a loop
- Very hard to do many simple things like getting the mouse position.
- Can only load gifs as sprites.
- Naming the file turtle.py: 1, 2.
- Terminating the Tkinter window usually throws a scary-looking, confusing error that isn't related to anything the user did wrong.
- Errors related to Tkinter are almost always confusing.
- No real turtle deallocation mechanism, so you're pretty much forced to write an object pool for apps with lots of turtles (particle systems, etc).
- Confusion using
printorinput(). - Collecting text input removes key listeners.
- Errors changing colors.
- Typoing key names (lowercase/uppercase), or generally being confused by the list of Tkinter keys.
- Overwriting the
turtlemodule with a variable calledturtle. - Making a clickable button with text (and hovering) is difficult.
- IDEs/linters can't figure out turtle types properly:
- PyCharm false syntax error using turtle
- Turtle Library Python: What am I doing when I do screen = Screen() if Screen isn't a class? (two issues, one being the IDE failing to identify a valid method on an object and the other being the
Screen()being a function in spite of the uppercased name)
- Calling functions immediately that should be passed to
ontimeror listeners - Accurate timing for animations
- undefined fill behavior
- No good way to relaunch a screen after closing it
- Forgetting to call methods and 'str' object has no attribute 'turtle' in Python turtle
- Assigning to methods rather than calling them
- Turtles are weirdly off center for no reason (TODO: verify and investigate)
- Bugs binding keypresses without a closure: Dynamically passing Turtles to onkeypress() binds always only one of them
- Differences in the turtle API between Python 2 and Python 3:
- Forgetting to provide a number argument to
ontimer.- How to manage event-handler recursion in python turtle? (unable to reproduce on a modern machine but worth looking into)
- Calling
clearscreen()removesexitonclick()handler: Why isn't exitonclick working in my Python Turtle graphics program? - Calling
.clear()in the wrong place - There are other similar libraries like Google colab turtle, replit, and trinket that are incompatible with the CPython turtle.
- For example, they have different arguments
onkeyreleasefires even if you haven't released the key, if the OS retrigger kicks in.- Changing the turtle's shape removes click handlers
- Screen size is slightly off on different systems
- Turtle can fail out of the box with a confusing error on Mac: DEPRECATION WARNING: The system version of Tk is deprecated, M1 Mac in Vs Code - global Python
- Forgetting to add parentheses to a function call--not specific to turtle, but definitely a Python gotcha that hits beginners.
- Possible: did colormode change from turtle to screen? check here and add to list if so
TODO: make a library that fixes these issues and offers a real rendering loop (with delta time). Or maybe suggest people use JS or Lua/Love or Pygame.