visibility – How to hide a turtle icon/pointer in Python

visibility – How to hide a turtle icon/pointer in Python

The documentation has a section on Visibility:

turtle.hideturtle()
turtle.ht()
Make the turtle invisible. It’s a good idea to do this while you’re in the middle of doing some complex drawing, because hiding the turtle speeds up the drawing observably.

>>> turtle.hideturtle()

Also, you can un-hide the turtle:

turtle.showturtle()
turtle.st()
Make the turtle visible.

>>> turtle.showturtle()

You can also query its visibilty:

turtle.isvisible()
Return True if the Turtle is shown, False if it’s hidden.

>>> turtle.hideturtle()
>>> turtle.isvisible()
False
>>> turtle.showturtle()
>>> turtle.isvisible()
True

One more practical method that the other answer failed to address is to set the visible keyword argument to False when defining the Turtle object:

import turtle

my_turtle = turtle.Turtle(visible=False)

Of course, that is for when you want the Turtle to be invisible from the very beginning of the program.

When you define a Turtle object without setting visible to False, there will always be a lightning short moment where the turtle is still visible:


import turtle

my_turtle = turtle.Turtle()
# The Turtle may be visible before the program reaches the line under, depending on the speed of your computer 
my_turtle.hideturtle()

With the visible keyword argument set to False, you can always call my_turtle.showturtle() and my_turtle.hideturtle() in your code where ever the Turtle needs to be visible and hidden again.


Here are all the default turtle settings that you can customize (the settings of interest here are the ones commented with the # RawTurtle):

_CFG = {width : 0.5,               # Screen
        height : 0.75,
        canvwidth : 400,
        canvheight: 300,
        leftright: None,
        topbottom: None,
        mode: standard,          # TurtleScreen
        colormode: 1.0,
        delay: 10,
        undobuffersize: 1000,      # RawTurtle
        shape: classic,
        pencolor : black,
        fillcolor : black,
        resizemode : noresize,
        visible : True,
        language: english,        # docstrings
        exampleturtle: turtle,
        examplescreen: screen,
        title: Python Turtle Graphics,
        using_IDLE: False
       }

Update: I just noticed that cdlanes comment on the other answer pointed out this method, but comments are temporary.

visibility – How to hide a turtle icon/pointer in Python

Leave a Reply

Your email address will not be published.