1

Hey im a newbie in python in my code there is a animated gif that play whenever i run the code. The gif image is actually transparent when open in adobe etc. but the problem is when i run the code.The frame which is the color gray included in the gif.I want to remove the color gray so that the only thing that can see is my only animated gif

This is my code:

# mimic an animated GIF displaying a series of GIFs
# an animated GIF was used to create the series of GIFs 
# with a common GIF animator utility

import time
from Tkinter import *

root = Tk()

imagelist = ["dog001.gif","dog002.gif","dog003.gif"]

# extract width and height info
photo = PhotoImage(file=imagelist[0])
width = photo.width()
height = photo.height()
canvas = Canvas(width=width, height=height)
canvas.create_line(0,240,640,240, fill='blue')
canvas.pack()

# create a list of image objects
giflist = []
for imagefile in imagelist:
    photo = PhotoImage(file=imagefile)
    giflist.append(photo)

# loop through the gif image objects for a while
for k in range(0, 10):
    for gif in giflist:
        canvas.delete(ALL)
        canvas.create_image(width/2.0, height/2.0, image=gif)
        canvas.update()
        time.sleep(0.1)

root.mainloop()[![enter image description here][1]][1]

dog001.gif

dog002.gif

dog003.gif

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

3

As described here, making a Tkinter window transparent is possible, but depends on your OS.

If you are on Windows, just add the following lines after creating the root:

root = Tk()
# Hide the root window drag bar and close button
root.overrideredirect(True)
# Make the root window always on top
root.wm_attributes("-topmost", True)
# Define a transparent color
root.wm_attributes("-transparentcolor", '#eeefff')

Then set your canvas' background color as the transparent color defined above:

canvas = Canvas(width=width, height=height, bg='#eeefff', highlightthickness=0)

screenshot

Josselin
  • 2,593
  • 2
  • 22
  • 35