Advertisement
here2share

# Tk_mimicgifs.py

Oct 3rd, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # Tk_mimicgifs.py
  2.  
  3. # mimic an animated GIF displaying a series of images
  4.  
  5. import time
  6. from Tkinter import *
  7. import tkFileDialog
  8. import sys
  9. import os
  10.  
  11. root = Tk()
  12.  
  13. class Cv(): 0
  14. cv = Cv
  15. cv.path = ''
  16.  
  17. oFiletype =("gif files","*.gif"),("jpg files","*.jpg"),("png files","*.png"),("all files","*.*")
  18. def askfolder():
  19.     cv.path = tkFileDialog.askopenfilename(title = "Select file",filetypes=oFiletype)
  20.     cv.path = os.path.dirname(cv.path)+'/'
  21.  
  22. canvas = Canvas(width=99, height=99)
  23. canvas.pack()
  24.    
  25. while 1:
  26.     askfolder()
  27.     cv.ani = [cv.path+z for z in os.listdir(cv.path) if z.endswith(('.gif','.jpg','.png'))]
  28.  
  29.     # extract width and height info
  30.     photo = PhotoImage(file=cv.ani[0])
  31.     wt = photo.width()
  32.     ht = photo.height()
  33.    
  34.     canvas.config(height=ht, width=wt)
  35.    
  36.     try:
  37.         # loop through the series of images
  38.         for k in range(0, 200):
  39.             photo = PhotoImage(file=cv.ani[k%len(cv.ani)])
  40.             canvas.create_image(wt/2.0, ht/2.0, image=photo)
  41.             canvas.update()
  42.             time.sleep(0.05)
  43.     except:
  44.         break
  45. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement