Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from PIL import Image, ImageTk
- from itertools import count, cycle
- canvas= Canvas(width=300,height=400,bg='white')
- canvas.pack(expand=YES, fill=BOTH)
- class ImageLabel(Label):
- def load(self, im):
- if isinstance(im, str):
- im = Image.open(im)
- frames = []
- try:
- for i in count(1):
- frames.append(ImageTk.PhotoImage(im.copy()))
- im.seek(i)
- except EOFError:
- pass
- self.frames = cycle(frames)
- try:
- self.delay = im.info['duration']
- except:
- self.delay = 100
- if len(frames) == 1:
- self.config(image=next(self.frames))
- else:
- self.next_frame()
- def unload(self):
- self.config(image=None)
- self.frames = None
- def next_frame(self):
- if self.frames:
- self.config(image=next(self.frames))
- self.after(self.delay, self.next_frame)
- root = Toplevel()
- lbl = ImageLabel(root)
- lbl.load('images/k.gif')
- lbl.grid(row=0)
- lbl1 = ImageLabel(root)
- lbl1.load('images/k.gif')
- lbl1.grid(row=0,column=1)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement