-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloading.py
executable file
·68 lines (48 loc) · 1.72 KB
/
loading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
##### ~ http://stackoverflow.com/questions/7960600/python-tkinter-display-animated-gif-using-pil ~
## source of code can be found at the above web page, I have modified the code to suit my needs.
from Tkinter import *
from PIL import Image, ImageTk
class MyLabel(Label):
def __init__(self, master, filename):
im = Image.open(filename)
seq = []
try:
while 1:
seq.append(im.copy())
im.seek(len(seq)) # skip to next frame
except EOFError:
pass # we're done
try:
self.delay = im.info['duration']
except KeyError:
self.delay = 100
first = seq[0].convert('RGBA')
self.frames = [ImageTk.PhotoImage(first)]
Label.__init__(self, master, image=self.frames[0],
highlightthickness=0, bg='white')
temp = seq[0]
for image in seq[1:]:
temp.paste(image)
frame = temp.convert('RGBA')
self.frames.append(ImageTk.PhotoImage(frame))
self.idx = 0
self.cancel = self.after(self.delay, self.play)
def play(self):
self.config(image=self.frames[self.idx])
self.idx += 1
if self.idx == len(self.frames):
self.idx = 0
self.cancel = self.after(self.delay, self.play)
root = Tk()
anim = MyLabel(root, 'HangMan_img/loading/google.gif')
anim.place(x=140, y=90)
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.config(bg='white')
root.overrideredirect(1)
x = screen_width / 2 - 500 / 2
y = screen_height / 2 - 400 / 2
root.geometry('%dx%d+%d+%d' % (500, 400, x, y))
anim.after(2000, root.destroy)
root.mainloop()