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.bgpic()
This function is used to set a background image or return name of the current background image. It requires only one argument “picname”. This argument can be used in different ways as follows :
- If picname is a filename, set the corresponding image as background.
- If picname is “nopic”, delete background image, if present.
- If picname is None, return the filename of the current backgroundimage.
Syntax :
turtle.bgpic(picname=None)
Below is the implementation of the above method with some examples :
Example 1 :
Python3
# import package import turtle # check background image print (turtle.bgpic()) |
Output :
nopic
Example 2 :
Python3
# import package import turtle # set background image turtle.bgpic( "gfg.png" ) |
Output :
Example 3 :
Python3
# import package import turtle # set background image turtle.bgpic( "gfg.png" ) # loop for motion for i in range ( 20 ): turtle.forward( 5 + 5 * i) turtle.right( 90 ) # delete background image turtle.bgpic( "nopic" ) |
Output :