用gif更新tkinter窗口

时间:2019-01-01 10:42:58

标签: python tkinter

import tkinter as tk
import time
from tkinter import *
from tkinter import messagebox
from time import sleep
from PIL import Image, ImageTk
from itertools import count
from time import sleep

class ImageLabel(tk.Label):

    def load(self, im):
        if isinstance(im, str):
            im = Image.open(im)
        self.loc = 0
        self.frames = []

        try:
            for i in count(1):
                self.frames.append(ImageTk.PhotoImage(im.copy()))
                im.seek(i)

        except EOFError:
            pass

        try:
            self.delay = im.info['10']
        except:
            self.delay = 100

        if len(self.frames) == 1:
            self.config(image=self.frames[0])          
        else:
            for i in range(1):
                self.next_frame()

    def unload(self):
        self.config(image=None)
        self.frames = None

    def next_frame(self):
        if self.frames:
            self.loc += 1
            self.loc %= len(self.frames)
            self.config(image=self.frames[self.loc])
            self.after(self.delay, self.next_frame)

root = tk.Tk()
root.geometry('400x200')
root.title("מערכת הסבת וואלה מייל")
lbl = ImageLabel(root)
lbl.pack()
lbl.load('Logo.gif')

我运行了这段代码,我不知道在显示gif后如何更新tkinter胜利。

有人可以帮助我并告诉我该怎么做吗?我尝试了很多事情,但我不知道该怎么办。

1 个答案:

答案 0 :(得分:0)

当我在IDLE中运行此程序时,它似乎工作正常。 IDLE所做的事不在程序中,而是在运行mainloop。尝试添加为程序的最后一行:

function sleep(ms) { 
    var beginAnnounce = new Promise(...);
    var goSleep = new Promise (...);
    var endAnnounce = new Promise...);

    return beginAnnounce.then(goSleep).then(endAnnounce());

}