user11363434
user11363434

Reputation:

How to play GIF's using turtle module in Python?

I want the GIF to play in the turtle screen. But it is showing only the still image. Please fix this, Any help will be appreciated...

Here is my code:

import turtle
import os

# resources :
bgpic = r"C:\Users\intel\Desktop\xBDT7.gif"


win = turtle.Screen()
win.addshape(bgpic)

sh = turtle.Turtle()
sh.shape(bgpic)


# Shuting the window down :
turtle.mainloop()

Upvotes: 2

Views: 7549

Answers (2)

# in order to use GIF as shape you have to register them first
from turtle import Screen
from snake import Snake
from food import Food
from scoreboard import ScoreBoard
import time


screen = Screen()
screen.setup(width=600, height=600)
screen.bgpic("background.gif")
screen.title("Snake Game")
screen.tracer(0)
screen.register_shape("apple.gif")
screen.register_shape("snake.gif")
screen.register_shape("snake_head.gif")
screen.register_shape("snake_head_right.gif")
screen.register_shape("snake_head_up.gif")
screen.register_shape("snake_head_down.gif")

you can find more detailed information at https://docs.python.org/3/library/turtle.html#turtle.register_shape

Upvotes: 0

sewsam
sewsam

Reputation: 48

From reading the turtle documentation, here, I don't see anything that says animated gifs can be played within turtle. You are free to read the documentation yourself, but It appears that although to use an image as a shape or background in turtle, it needs to be a .gif file, you cannot actually playback animated gifs in turtle.

Upvotes: 2

Related Questions