Open In App

turtle.bgpic() 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.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 :



Syntax :

turtle.bgpic(picname=None)

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



Example 1 :




# import package
import turtle
  
# check background image
print(turtle.bgpic())

Output :

nopic

Example 2 :




# import package
import turtle
  
# set background image
turtle.bgpic("gfg.png")

Output :

Example 3 :




# 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 :


Article Tags :