how can I make png image to gif image?
You can use pillow’s ImageTk
to load the image directly as png.
import tkinter as tkfrom PIL import Image, ImageTkimage_o = Image.open("photo.png")image = ImageTk.PhotoImage(image_o)# Use image as to how you would in tkinter root = tk.Tk()button = tk.Button(root, image = image)button.pack()root.mainloop()
Unlike tkinter‘s PhotoImage, which limits you to use only a certain type of images including the widespread gif file, ImageTk’s PhotoImage can take any PIL recognizable image type by having pillow to load it first.
http://pillow.readthedocs.io/en/4.1.x/reference/ImageTk.html
If you don’t have pillow yet, do pip install pillow
Added: (thanks to Mike - SMT’s valuable comment)
In newer releases of tk/tkl 8.6+, tk natively supports png image format.
Warning: this version of tk isn’t supported in some python interpreters.