Skip to content

Instantly share code, notes, and snippets.

@mirwox
Created May 31, 2016 20:10
Show Gist options
  • Save mirwox/69683b41b039ef3aa89fe63e861465e4 to your computer and use it in GitHub Desktop.
Save mirwox/69683b41b039ef3aa89fe63e861465e4 to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
# Adapted from
# https://www.daniweb.com/programming/software-development/code/216550/tkinter-to-put-a-gif-image-on-a-canvas-python
import time
from tkinter import *
import time
from threading import Thread
root = Tk()
frame = Frame(root)
frame.pack()
current = 0
def animate_frame():
canvas.delete("all")
canvas.create_image(50 + current*2, 10, image = gifs[current], anchor = NW)
root.update()
time.sleep(0)
print("+", end=None)
global current
current +=1
current = current % len(gifs)
canvas.after(50, animate_frame)
# create the canvas, size in pixels
canvas = Canvas(frame, width=500, height=200, bd=0, highlightthickness=0)
# pack the canvas into a frame/form
canvas.pack(expand = YES, fill = BOTH)
# Load aniamted gifs
gifs = []
gifs.append(PhotoImage(file = 'metal_slug.gif'))
gifs.append(PhotoImage(file='metal_slug.gif', format="gif -index 3"))
gifs.append(PhotoImage(file='metal_slug.gif', format="gif -index 6"))
# Inicia as chamadas recorrentes que fazem animação
animate_frame()
mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment