Rich. T.
Rich. T.

Reputation: 53

Python Turtle - change displayed background image

I am writing a Python 3 turtle example program, and am trying to use bgpic() to change the displayed background image.

Here's a simplified version of my program:

import turtle
import time

screen = turtle.Screen()
screen.setup(600,400)
screen.bgpic('image1.gif')
time.sleep(2)
screen.bgpic('image2.gif')

When I run this program, I'd like to see the initial image, and then see the image change after 2 seconds. Instead, the screen stays blank until after the second image is drawn.

Any help appreciated, Thanks!

Upvotes: 1

Views: 24690

Answers (2)

ppasler
ppasler

Reputation: 3719

Adding a turtle and moving it made it work for me

import turtle

t = turtle.Turtle()
s = turtle.Screen()
s.setup(300, 300)
s.bgpic('image1.gif')


for i in range(180):
    t.color("black")
    t.fd(20)

Upvotes: 0

DYZ
DYZ

Reputation: 57033

Add screen.update() after the first screen.bgpic('image1.gif').

Upvotes: 6

Related Questions