VOOZH about

URL: https://www.geeksforgeeks.org/python/turtle-write-function-in-python/

โ‡ฑ turtle.write() function in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

turtle.write() function in Python

Last Updated : 15 Jul, 2025

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 :

Output:

๐Ÿ‘ Image

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.

Output:

๐Ÿ‘ Output
turtle.write() with center alignment

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.

Output:

๐Ÿ‘ Output
turtle.write() while moving

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.

Output:

๐Ÿ‘ output
text alignment with turtle.write()

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".

Comment
Article Tags:
Article Tags: