turtle.write() function in Python
turtle module in Python provides a way to create graphics and animations using Tkinter. The turtle.write() method is used to display text at the turtle’s current position on the canvas. This function helps in labeling graphics, adding instructions or displaying values dynamically. It allows both object-oriented and procedural programming approaches. Let's look at an example to better understand turtle.write() function :
import turtle
# write text
turtle.write("GeeksForGeeks")
Output:

Explanation: This code initializes the turtle module and uses the write() function to display the text "GeeksForGeeks" at the turtle's current position on the canvas. By default, the text is left-aligned and the turtle remains stationary after writing.
Syntax of turtle.write()
turtle.write(arg, move=False, align='left', font=('Arial', 8, 'normal'))
Parameters:
- arg: The text or value to be written on the TurtleScreen.
- move: Boolean (True or False). If True, the turtle moves to the end of the text.
- align: Specifies text alignment. Can be "left", "center", or "right".
- font: A tuple (fontname, fontsize, fonttype) specifying the font style.
Return value: This method does not return anything. Instead, it directly modifies the turtle canvas by displaying text at the specified position.
Examples of turtle.write()
Example 1: In this example, we use turtle.write() to display a simple text message at the turtle’s current position.
import turtle
t = turtle.Turtle()
# Write text at turtle's position
t.write("Hello, Turtle!", align="center", font=("Courier", 16, "bold"))
turtle.done()
Output:

Explanation: A Turtle object is created, and the write() method is used to display the text "Hello, Turtle!" at the turtle's current position. The text is centered using align="center" and styled with the Courier font, set to size 16 in bold.
Example 2: This example demonstrates how we can write text at different points while the turtle moves in a circular path.
import turtle
t = turtle.Turtle()
t.speed(3)
for _ in range(4):
t.write("Hello!", font=("Arial", 12, "normal"))
t.circle(50, 90)
turtle.done()
Output:

Explanation: The turtle starts by writing "Hello!" at its initial position. It then moves in a circular path using t.circle(50, 90), which makes a 90-degree turn with a radius of 50. This process repeats four times, allowing the turtle to complete a full circle while writing text at each quarter-turn.
Example 3: This example illustrates how to align text in different ways using the align parameter.
import turtle
t = turtle.Turtle()
t.write("Left Align", align="left", font=("Arial", 12, "normal"))
t.sety(-30)
t.write("Center Align", align="center", font=("Arial", 12, "normal"))
t.sety(-60)
t.write("Right Align", align="right", font=("Arial", 12, "normal"))
turtle.done()
Output:

Explanation: The turtle begins by writing "Left Align" at its starting position using align="left". It then moves downward with t.sety(-30) and displays "Center Align" at the new position using align="center". Moving further down to y = -60, the turtle writes "Right Align" with align="right".