Friday, November 15, 2024
Google search engine
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

Recent Comments