LEJ2474
LEJ2474

Reputation: 43

How to return an image using turtle.bgpic()

I'm trying to write a bit of code that will show me a picture of a map but when I run the code it's not returning the image or any sort of error. After doing a bit of research I don't think I need any other code but any help would be greatly appreciated.

import turtle
screen = turtle.Screen()
screen.setup(720,360)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('map.gif')

Upvotes: 2

Views: 937

Answers (2)

SamTheProgrammer
SamTheProgrammer

Reputation: 1185

Solution

To make the window stay open, you need screen.mainloop(). What this does is to keep the window open and run any code that is necessary such as key presses. You simply place this at the end of the code and the final code looks like this...

Code

import turtle
screen = turtle.Screen()
screen.setup(720,360)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('map.gif')
screen.mainloop()

Note: You need screen.mainloop() or turtle.mainloop() (if you haven't created a screen object) at the end of all turtle projects if you want them to run.

Upvotes: 2

chengi i
chengi i

Reputation: 21

Is it flash back?Maybe you need suspend the program because end of execution or add screen.mainloop() as one solution

Upvotes: 2

Related Questions