turtle.title() function in Python

The turtle.title() function sets the title of the turtle graphics window. This text appears in the title bar of the window.

Syntax: turtle.title(titlestring)
Parameters: titlestring – a string (the new title text for the window).

Let us see an example to implement the turtle.title() function in Python:

Demo59.py

# turtle.title() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
window.title("My Turtle Drawing Program")  # Set window title

t = turtle.Turtle()
t.forward(100)

window.exitonclick()

The following is the output:

turtle.title() function in Python

In the above code, we followed the below steps:

  • Import module: import turtle loads the turtle graphics library.
  • Create screen: window = turtle.Screen() opens the drawing window.
  • Set window title:title(“My Turtle Drawing Program”) changes the title text shown in the window’s title bar.
  • Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
  • Move forward:forward(100) draws a 100-unit line (pen down by default).
  • Close on click:exitonclick()

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.screensize() function in Python
turtle.bye() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment