How Can I Print “Hello World” Python Turtle’s Write Function?

Turtle’s Write Function

All coding languages can communicate with the user in some way. Most can display text – messages, error messages etc. In Python Turtle, the write function lets the coder display text on the output screen.

Yes, Python’s Turtle CAN Output Text!

How to Use the Turtle Write Function

This function is quite easy to use:

It has the same syntax as Python’s print function, which means it also needs the brackets and quotes to work.

The write function will also output the result of an arithmetic statement:

There is one important feature that the coder must remember:

The write function displays the output wherever the turtle happens to be at that point, but it doesn’t move the actual turtle position, so two write functions will overwrite each other unless the turtle’s position has moved.

Write Function Output

This function uses the turtle graphics window, which is measured in pixels, not rows and columns. This means that the turtle can place the text or string at a specific location!

setpos(x, y) moves the turtle to the (x, y) coordinate within the function brackets. This function is very versatile. It can move the turtle anywhere in the output window for any of its other functions, including the graphics functions.

What the Font?

The default font is Arial normal 8 point and appears quite small in the output window compared to 20 point size.

Luckily, the write function gives the coder a lot of control over how information is displayed to the user.

write( ) can specify any system font, size and style:

The only issue is that can be hard to accurately determine the best setpos(x, y) coordinates when multiple turtle write functions are used.

Exploring the Turtle Write Function

The only way to truly understand how this function works is to test it:

Of course, it’s easy to make coding mistakes:

It’s important to understand how to produce errors so they can be avoided.

The Turtle Advantage

Building full programs with graphics and text output make coding much more fun.

turtle-write-function-with-for-loops-resource

Here is a resource that will explore this function. It includes answer keys as well as lessons with teacher notes.

You can also buy the full unit (which includes a test) here.

turtle-write-function-with-for-loops-unit

This unit includes Online Learning slides with embedded videos that can be used in Google Classroom on Microsoft One Drive, as well as a zipped PDF file with slides, answer keys, rubrics and code exemplars.

More Resources