'How can I remove an bgimage in Python Turtle

I imported an bg image like so

screen = turtle.Screen()


#reference image
screen.bgpic("image.png")

then I made my graphic but I want to remove the bg image so only the bgcolor remains and if I screen.clear() it clears everything I drew with turtle.



Solution 1:[1]

Per the documentation, pass 'nopic' as the picname argument and it will remove the current image:

bgpic(picname=None)
    Set background image or return name of current backgroundimage.
    
    Optional argument:
    picname -- a string, name of a gif-file or "nopic".
    
    If picname is a filename, set the corresponding image as background.
    If picname is "nopic", delete backgroundimage, if present.
    If picname is None, return the filename of the current backgroundimage.

The 'nopic' token is also returned when interrogating bgpic() if there is no background image set:

% python3
Python 3.8.3 (v3.8.3:6f8c8320e9, May 13 2020, 16:29:34) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
>>> turtle.bgpic()
'nopic'
>>> 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cdlane