Loading video player…

Getting Started With Turtle

00:00 Getting Started with turtle. Pre-requisites. As turtle is built into Python, there are only a couple of things that you’ll need. Firstly, Python. This may seem somewhat obvious, but you’ll need Python 3 installed on your computer to follow along.

00:17 This will need to be on a computer with a graphical user interface, such as Windows, macOS, or a desktop version of Linux. Put simply, if you use a mouse to control your computer, you should be okay.

00:30 Python 3 can be downloaded from the Python website, python.org. And if you need help, take a look at the Real Python guide by following this link or searching on the Real Python site.

00:43 Python Environment. For much of this course, you’ll see the Python REPL being used. This allows entry of Python commands and their instant execution. For the final project, the code will be written in an editor as this code is longer and more complex than any of the previous examples, and it will be built up in stages.

01:04 In my case, I’ll be using Visual Studio Code, but you can use any editor such as IDLE, which is installed alongside Python. And that’s it! You’re ready to start using Python turtle, so let’s head into the next section and see it in action.

01:19 Getting turtle On Screen. Here, you will see how to move towards using turtle. The terminal command prompt is what’s needed to run the Python REPL, so we’ll just take a quick look at how to launch on macOS, Linux, and Windows.

01:36 On macOS, summon Spotlight Search by holding down the Command key and tapping the Spacebar. You can then type “terminal” and hit Enter once it appears at the top of the search.

01:51 On Ubuntu Linux, tap the Windows or Command key depending on the hardware you’re running on, and then type “terminal”. Once again, when it’s the highlighted choice, you can launch it using Enter.

02:07 On Windows, you’re looking for the command prompt. Tap the Windows key and type the first parts of “command” until it appears highlighted on the Start menu. You can then run it with Enter.

02:23 Next, a quick word about the REPL itself: you can run it by typing python or sometimes python3 and you should see the prompt ready for you to enter commands.

02:34 The Python REPL is perfectly functional and it will run every command that you see in this course, but throughout, I will be making use of bpython, which is an improved REPL.

02:43 It features color coding as well as onscreen information about available functions and what parameters they take. Once you’re in the REPL of your choice, the first step is to import turtle.

02:55 This allows Python to use the turtle commands that we’ll be using throughout this course. Whenever you start a new Python session and want to use turtle, you’ll need to enter this line.

03:07 Don’t be afraid to start again by exiting using exit(). This will destroy the turtle window when Python stops running. Then simply run the REPL and import turtle again.

03:19 Import and Naming Conventions. The Python documentation example imports turtle using this command: from turtle import *. This has good and bad points, but I wouldn’t recommend it for a beginner, simply because then it’s not easy to tell if a command is a built-in Python command or if it’s part of the turtle library. Instead, make use of import turtle as previously seen.

03:44 This is easier to understand because every method will be preceded by the word turtle and a dot (.).

03:51 When you’re first experimenting with turtle, you can use the turtle objects and methods without any reference. For instance, you can just type turtle.getscreen() and a screen will appear.

04:03 The other commands used for controlling the turtle will also work in the same way, but this can mean a lot more typing and it’s much easier to assign a variable name to them, a bit like naming a pet, as then you know you are always referring to the correct object.

04:19 Whenever you choose a variable name, try to balance making it meaningful with keeping it succinct. When you come back to your code in a few weeks time, it makes reading the code so much easier if the variable names make sense.

04:33 Initially, you will see s used to refer to the screen and t to refer to a turtle. With that out of the way, let’s look at programming Python turtle, exploring the features and functions that are present.

Become a Member to join the conversation.