【发布时间】:2021-02-16 06:19:11
【问题描述】:
我正在尝试从 gif 文件夹中加载 gif,该文件夹由 txt 文档上的数字选择。它正在选择正确的,但我不知道如何从选定的 gif 中获取帧数。 到目前为止的代码如下:
from tkinter import *
from PIL import Image, ImageTk
from time import sleep
import os
root = Tk()
root.title("displaygif")
root.geometry("404x484")
with open('wantedgif/wantedgif.txt') as wantedgif: #This is the file where the ID for the gif is
gifID = wantedgif.readline(3)
print (gifID)
line_number = 0
with open("CodeRef/gifIDList.txt", 'r') as read_obj: #This is the file that has the ID and what
the gif names are, under there respective ID
for line in read_obj:
line_number += 1
if gifID in line:
line_number -= 1
gif = read_obj.readlines()
print(gif[line_number]) #This all seems to work fine
im = Image.open('gif/' + gif[line_number].strip() + '.gif') #Opens the gif using the gif name
我不知道如何计算 gif 中的帧数,以及如何显示它。我已经搜索了几个小时,但找不到任何有用的东西。最好不要导入其他任何东西,但这并不重要。提前致谢。
【问题讨论】:
-
所以你发布的代码实际上与你的实际问题基本无关?
-
怎么会这样?
-
你正在从文本文件中读取一堆标签;这些操作与您询问的问题完全无关。
标签: python tkinter python-imaging-library