How can I save TKinter PhotoImage to .GIF?

Can I save a tkinter PhotoImage as .gif (or any other image extension) using only Python and tkinter?


Assuming photo is the variable holding your image, you should be able to just say:

photo.write('some_name.gif', format='gif')

I couldn't find a list of what formats are supported, but I think the list is really limited (I can confirm that gif worked for me though).


Looks like the method write can be used to save a PhotoImage to a file.

>>> help(Tkinter.PhotoImage.write) Help on method write in module Tkinter: write(self, filename, format=None, from_coords=None) unbound Tkinter.PhotoImage method Write image to file FILENAME in FORMAT starting from position FROM_COORDS.

Sample usage would be something like:


人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:How can I save TKinter PhotoImage to .GIF?