Being Creative With Turtles

Apr 11, 2024

Artistic Turtle

Turtle is a module built into Python itself. The Turtle Class allows the user to directly adjust and interact with the Graphical User Interface (GUI). The Turtle module uses Classes to create Objects, if you’d like to learn more about Classes, Objects, Attributes and Methods before continuing please click here. To use the Turtle module, you must first import it, or you can get hold of the Turtle class directly by writing from the Turtle module import the Turtle class and then calling the Turtle class and tying it to an Object:

from turtle import Turtle
theo = Turtle()
print(theo)
#Result
<turtle.Turtle object at 0x000001CA43C714C0>
The alphanumeric name “0x000001CA43C714C0” isn’t as important as what it represents, it is a specific location in the computer’s memory. This means that the object has been created and is stored in the location “0x000001CA43C714C0” in the memory of the computer. This is different that printing a string or doing a simple calculation; the object itself is not only a virtual entity, but also being held in the memory of the computer.

The Turtle module is capable of:

Creating a Screen:

Screen is another Class built into the Turtle module, its entire purpose is to present a visual representation of the Turtle Object that you have created with all attributes and any methods you chose to use with it. The Screen however will immediately close unless the method exitonclick() is used to preserve the screen until specifically told to close.

from turtle import Screen
my_screen = Screen()
my_screen.exitonclick()

Change the shape of you Object:

A Turtle presented on a screen will automatically show as an arrow, however you can choose a different shape to display on your window. Turtle comes with these shapes already built in:
  • Arrow
  • Turtle
  • Circle
  • Square
  • Triangle
  • Classic (which is an arrow)

from turtle import Turtle, Screen
my_screen = Screen()
theo = Turtle()
theo.shape(“turtle”)
my_screen.exitonclick()

Drawing:

You can think of the Turtle object as having a pen attached to its body and anywhere it goes it will draw a continuous line. An example of how to use the Turtles ability to draw is through an etch-a-sketch program you can find here.

Creation of an OOP Game:

The Turtle module will automatically draw a continuous line unless told specifically not to by using the method penup(). Once you have an object that can move around the screen without a continuous line you can create multiple Objects from a single Class to start populating a game. If you’d like to see how to make multiple Objects from a single Class, click here. If you’d like to see examples of games created with the Turtle module, choose from the list below:
Justin.TadrosJustin Tadros is a Project Manager and Data Analyst at The Training Boss. Justin has a bachelor's degree in Theater performance from Rollins College and currently pursuing his master's in business at the University of Center Florida.  Justin is certified on Microsoft Power BI and Progress Sitefinity Sales accreditation with ongoing training on Python and CMS technologies.  Justin performs in theaters in Orlando, Boston, Alaska and standup comic whenever the opportunity arises.  His passion for performing and bringing incredible customer service to any industry he approaches is second to his commitment, dedication and hard work.

Tags:

Playlist for Sitefinity on YouTube

 

Playlist for Microsoft Fabric on YouTube

 

Playlist for AI on YouTube

Copyright © 2024 The Training Boss LLC

  Developed with Sitefinity 15.1.8321 on ASP.NET 8