turtle.getscreen() function in Python

The turtle.getscreen() function returns the TurtleScreen object that the turtle is drawing on. This object gives access to methods like setup(), bgcolor(), and listen().

Syntax: turtle.getscreen()
Parameters: None.

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

Demo67.py

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

import turtle

t = turtle.Turtle()

# Get the screen object from a turtle
screen = t.getscreen()
screen.title("Accessed through turtle")

t.forward(100)

screen.exitonclick()

The following is the output:

turtle.getscreen() function in Python

In the above code, we followed the below steps:

  • Import module: import turtle loads the turtle graphics library.
  • Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
  • Get screen from turtle: screen = t.getscreen() retrieves the Screen object associated with this turtle.
  • Set window title:title(“Accessed through turtle”) changes the title text in the window’s title bar.
  • Move forward:forward(100) draws a 100-unit line (pen down by default).
  • Close on click:exitonclick() waits for a mouse click, then closes the window.

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.get_shapepoly() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment