Thursday, July 17, 2025
HomeLanguagesturtle.screensize() function in Python

turtle.screensize() function in Python

The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.

turtle.screensize()

This method is used to resize the canvas the turtles are drawing on. If no arguments are given, this function returns the current (canvaswidth, canvasheight).

Syntax :

turtle.screensize(canvwidth=None, canvheight=None, bg=None)

Parameters:

Arguments Value Description
canvwidth positive integer new width of canvas in pixels
canvheight positive integer new height of canvas in pixels
bg colorstring or color-tuple new backgroundcolor

Below is the implementation of the above method with some examples :

Example 1 :

Python3




# import package
import turtle
  
  
# check the screensize by default
# it varies ide to ide
print(turtle.screensize())


Output :

(400, 300)

Example 2 :

Python3




# import package
import turtle
  
  
# set screen
turtle.screensize(canvwidth=400, canvheight=400,
                  bg="yellow")


Output :

Example 3 :

Python3




# import package
import turtle
  
# set turtle
turtle.width(2)
turtle.speed(10)
  
# loop for pattern
for i in range(10):
    turtle.circle(40)
    turtle.right(36)
  
# set screen and drawing remain as it is.
turtle.screensize(canvwidth=400, canvheight=300,
                  bg="blue")


Output :

RELATED ARTICLES

Most Popular

Dominic
32143 POSTS0 COMMENTS
Milvus
67 POSTS0 COMMENTS
Nango Kala
6526 POSTS0 COMMENTS
Nicole Veronica
11674 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11729 POSTS0 COMMENTS
Shaida Kate Naidoo
6616 POSTS0 COMMENTS
Ted Musemwa
6893 POSTS0 COMMENTS
Thapelo Manthata
6585 POSTS0 COMMENTS
Umr Jansen
6573 POSTS0 COMMENTS