Advertisement
AceScottie

tkinter_custom_Guage.py

Mar 13th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. from tkinter import *
  2. import PIL.Image, PIL.ImageTk, PIL.ImageDraw, PIL.ImageFont
  3. from itertools import count
  4. class Guage(Label):
  5.     def load(self, im):
  6.         if isinstance(im, str):
  7.             im = PIL.Image.open(im)
  8.         self.loc = 0
  9.         self.frames = []
  10.         try:
  11.             for i in count(1):
  12.                 self.frames.append(PIL.ImageTk.PhotoImage(im.copy()))
  13.                 im.seek(i)
  14.         except EOFError:
  15.             pass
  16.  
  17.         try:
  18.             self.delay = im.info['duration']
  19.         except:
  20.             self.delay = 100
  21.         if len(self.frames) == 1:
  22.             self.config(image=self.frames[0])
  23.     def unload(self):
  24.         self.config(image=None)
  25.         self.frames = None
  26.     def progress(self, p):
  27.         if isinstance(p, int):
  28.             if self.frames:
  29.                 print(p)
  30.                 print(len(self.frames))
  31.                 if p <= len(self.frames)-1:
  32.                     self.config(image=self.frames[p])
  33.                 else:
  34.                     self.config(image=self.frames[len(self.frames)-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement