turtle.getscreen() function in Python
The turtle.getscreen() function returns the TurtleScreen object on which the turtle is drawing. This object represents the canvas or window where all turtle graphics appear. By accessing the TurtleScreen object, you can use additional screen-related methods such as bgcolor(), title(), setup() directly.
Syntax :
turtle.getscreen()
- Parameters: This function takes no arguments.
- Returns: A TurtleScreen object representing the window or canvas where the turtle is currently drawing.
Examples
Example 1 : Printing the screen object
import turtle
sc = turtle.getscreen()
print(sc)
turtle.done()
Output :
<__main__.Screen object>
Explanation: Here, getscreen() returns the Screen object of the turtle graphics window, which can be printed or stored in a variable.
Example 2 : Changing background color using the screen object
import turtle
sc = turtle.getscreen() # get the screen object
sc.bgcolor("lightblue") # change background color
sc.title("My Turtle Screen") # set window title
turtle.forward(100)
turtle.done()
Output :

Explanation: The sc object is the TurtleScreen, so you can call screen-specific methods (bgcolor, title, etc.) directly on it.
Related Articles