English 中文(简体)
p t
原标题:python tkinter display animated GIF using PIL

是否有办法在Tkinter利用Adhur图像图书馆展示一个消化的全球信息论坛?

我想ImageSequence 模块是这样做的途径,但我不知道如何使用,如果可能的话。

第一个问题是,是否容易。 例如:使用PIL和图像Sequence装设一个全球电子数据系统,然后使用<代码>ImageTk.PhotoImage将其提用一个Tkinter窗口。

或者,我是否必须利用<条码>之后的<条码>方法,或者像<条码> 时间.sleep

第二个问题:即使我必须履行通过全球投资论坛框架的职能,图像数据模块是否应该这样做,或者消费物价指数是否拥有另一个模块?

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil”rel=“nofollow noretinger”> PIL私人港,见topic

问题回答

Newsgroups: comp.lang.python

“Fredrik Lundh”

日期:莫 2006年5月1日

Daniel Nogradi写道:

The source distribution of the 1.1.4 version comes with a Scripts directory where you can find player.py, gifmaker.py and explode.py which all deal with animated gif.

他们仍用1.1.5(和1.1.6)重新运输,应当工作。

if all you re missing is a few files from the script directory, you can get them here:

http://svn.effbot.org/public/pil/casts/


参与者来自指挥线。

see if this one works for you:

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()

简略版本:

canvas = Image.new("RGB",(Width,Height),"white")
gif = Image.open( text.gif ,  r )
frames = []
try:
    while 1:
        frames.append(gif.copy())
        gif.seek(len(frames))
except EOFError:
    pass

for frame in frames:
     canvas.paste(frame)
     canvas.show()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签