-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Bad image grab from GIF file by tkinter.PhotoImage with option format 'gif -index indexValue' #93510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like |
Following code show each frame and it looks that
import tkinter as tk
def next_one():
global index, image
index = (index+1) % n_frames
image = tk.PhotoImage(file=filename, format=f'gif -index {index}')
label.configure(image=image)
text.configure(text=f'Frame {index}')
filename = '1ac.gif' # https://cdn2.thecatapi.com/images/1ac.gif
n_frames = 52
root = tk.Tk()
index = 0
image = tk.PhotoImage(file=filename, format=f'gif -index {index}')
label = tk.Label(root, image=image)
label.pack()
text = tk.Label(text='Frame 0')
text.pack()
button = tk.Button(root, text='Next', command=next_one)
button.pack()
root.mainloop() If so, how it can be painted to widget ?
import tkinter as tk
def next_one():
global index, image
index = (index+1) % n_frames
image = tk.PhotoImage(file=filename, format=f'gif -index {index}')
canvas.create_image(0, 0, anchor=tk.NW, image=image)
text.configure(text=f'Frame {index}')
filename = '1ac.gif' # https://cdn2.thecatapi.com/images/1ac.gif
n_frames = 52
root = tk.Tk()
index = 0
image = tk.PhotoImage(file=filename, format=f'gif -index {index}')
canvas = tk.Canvas(root, width=500, height=211)
canvas.pack()
canvas.create_image(0, 0, anchor=tk.NW, image=image)
text = tk.Label(text='Frame 0')
text.pack()
button = tk.Button(root, text='Next', command=next_one)
button.pack()
root.mainloop() |
Tk supports the For now, your only options either to use third-party libraries like PIL, or call Tk directly from Python: accumImage.tk.call(accumImage, 'copy', deltaImage) (note that attributes I think that we can add a new method for this. But we should also think about more general solution. |
It work fine by using the method import tkinter as tk
def next_one():
global index, accumImage
index = (index+1) % n_frames
deltaImage = tk.PhotoImage(file=filename, format=f'gif -index {index}')
accumImage.tk.call(accumImage, 'copy', deltaImage)
canvas.create_image(0, 0, anchor=tk.NW, image=accumImage)
text.configure(text=f'Frame {index}')
filename = '1ac.gif' # https://cdn2.thecatapi.com/images/1ac.gif
n_frames = 52
root = tk.Tk()
index = 0
accumImage = tk.PhotoImage(file=filename, format=f'gif -index {index}')
canvas = tk.Canvas(root, width=500, height=211)
canvas.pack()
canvas.create_image(0, 0, anchor=tk.NW, image=accumImage)
text = tk.Label(text='Frame 0')
text.pack()
button = tk.Button(root, text='Next', command=next_one)
button.pack()
root.mainloop() |
Bug report
Bad image grab from the GIF file by tkinter PhotoImage with option format 'gif -index indexValue'.
This issue happened at lot of GIF image files, not only for this special GIF image.
In following image, there are 52 frames, it is enough, only first two frames to show this issue.
PhotoImage
with option format 'gif -index indexValue'PIL.Image
Script to demo
Environment
WIN10 / Pillow 9.1.1
python 3.7.9 / tkinter 8.6.9
python 3.8.10 / tkinter 8.6.9
python 3.9.9 / tkinter 8.6.12
python 3.10.1 / tkinter 8.6.12
The text was updated successfully, but these errors were encountered: