turtle.bgpic() function in Python
Last Updated :
28 Jul, 2020
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 turtle
print (turtle.bgpic())
|
Output :
nopic
Example 2 :
Python3
import turtle
turtle.bgpic( "gfg.png" )
|
Output :
Example 3 :
Python3
import turtle
turtle.bgpic( "gfg.png" )
for i in range ( 20 ):
turtle.forward( 5 + 5 * i)
turtle.right( 90 )
turtle.bgpic( "nopic" )
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...