뉴스 그룹 : "프레드릭 룬트 (Fredrik Lundh)"
날짜 : 2006년 (월)
다니엘 Nogradi 쓴 5월 1일 :
'소스 배포판에서 comp.lang.python
1.1.4 버전의 디렉토리에는 animated gif를 모두 다루는 player.py, gifmaker.py 및 explode.py 이 있습니다. '
이들은 여전히 1.1.5 (및 1.1.6)와 함께 제공되며 작동해야합니다. 당신이 놓치고있는 모든 스크립트 디렉토리에서 몇 개의 파일 인 경우
, 당신은 그들을 여기 를 얻을 수 있습니다 :
http://svn.effbot.org/public/pil/Scripts/
player.py 명령 줄에서 실행
이 하나가 작동하는지 확인하십시오.
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])
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, 'animated.gif')
anim.pack()
def stop_it():
anim.after_cancel(anim.cancel)
Button(root, text='stop', command=stop_it).pack()
root.mainloop()
고맙지 만, 저는 Python을 처음 접했을 때 실제로 스크립트를 어떻게 사용합니까? tkinter, PIL 및 player를 가져 왔고 이미 이미지를 열었습니다.'animation = player.UI (root, im) '및 몇 가지 변형을 시도했습니다. 플레이어 스크립트의 UI 클래스가 Label입니까? pack()하려고하면 "UI 객체에는 tk 속성이 없습니다"라고 표시되고 pack() 또는 grid()를 수행하지 않으면 아무 일도 일어나지 않습니다. –