• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / How to Hide Turtle in Python with hideturtle() Function

How to Hide Turtle in Python with hideturtle() Function

February 23, 2022 Leave a Comment

When using the turtle Module in Python, we can hide the turtle by using the hideturtle() function.

import turtle

t = turtle.Turtle()

def draw_circle(radius):
    t.circle(radius)

draw_circle(100)

t.hideturtle()

The turtle module in Python allows us to create graphics easily in our Python code.

We can use the turtle module to make all sorts of shapes in Python. For example, we can draw circles and draw squares easily in Python with the turtle module.

When working with our turtle, sometimes it makes sense to want to hide a turtle.

We can easily hide a turtle in Python with the hideturtle() function.

Below is an example of drawing a circle and then hiding the turtle after the turtle is done in Python.

import turtle

t = turtle.Turtle()

def draw_circle(radius):
    t.circle(radius)

draw_circle(100)

t.hideturtle()

How to Initialize and Hide Turtle in Python

Another way to hide a turtle in Python is to pass the ‘False’ to the keyword ‘visible’ when initializing the turtle.

This will create a hidden turtle in your turtle window.

Below is the Python code to initialize a hidden turtle.

import turtle

t = turtle.Turtle(visible=False)

How to Check if a Turtle is Visible in Python

To check if a turtle is visible or not, use the turtle isvisible() function. The isvisible() function returns True if the turtle is visible and False if the turtle is hidden.

Below is an example showing how to use the Python turtle isvisible() function to check if a turtle is visible or not.

import turtle

t = turtle.Turtle(visible=False)

print(t.is_visible())

t.showturtle()

print(t.is_visible())

#Output:
False 
True

How to Show a Hidden Turtle in Python

There are also turtle functions which allow us to show hidden turtles. We can use the showturtle() function to show a hidden turtle.

Below is an example of drawing a circle with an invisible turtle and then showing the turtle after completion in Python.

import turtle

t = turtle.Turtle(visible=False)

def draw_circle(radius):
    t.circle(radius)

draw_circle(100)

t.showturtle()

Just like with the hideturtle() function, we can use a shorter function name to show a turtle. You can use st(), the short version of showturtle(), as shown below.

import turtle

t = turtle.Turtle(visible=False)

def draw_circle(radius):
    t.circle(radius)

draw_circle(100)

t.st()

Hopefully this article has been useful for you to hide a turtle in your Python programs.

Other Articles You'll Also Like:

  • 1.  Does Python Use Semicolons? Why Python Doesn’t Use Semicolons
  • 2.  Truncate Decimal from Number with Python math.trunc() Function
  • 3.  Python Prepend to List with insert() Function
  • 4.  Python Check if List Index Exists Using Python len() Function
  • 5.  Get Difference Between datetime Variables in Python
  • 6.  Check if Character is Letter in Python
  • 7.  Get Substring Between Two Characters with Python
  • 8.  How to Remove Vowels from a String in Python
  • 9.  Find Maximum of Three Numbers in Python
  • 10.  How to Check If File is Empty with Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy