Python 2.7 display jpeg image contained in zip file Python 2.7 display jpeg image contained in zip file tkinter tkinter

Python 2.7 display jpeg image contained in zip file


I was able to create a seekable memory file from a (nonseekable) ZipFile object as follows:

from io import BytesIOimport zipfilefrom PIL import Image, ImageTk...zfile = zipfile.ZipFile(filename,'r')  # non-seekablememberlist = zfile.namelist()...zfiledata = BytesIO(zfile.read(membername)) # seekableimage = Image.open(zfiledata)  # image.show() will displayphoto = ImageTk.PhotoImage(image)

Photo can then be used in any Tk widget which takes an image object (e.g., Canvas, Label, etc.)

On my first try of the above code, I got an error message about missing files. Apparently ImageTk is not part of the standard 2.7 installation. Instructions for installing it I found in a SO post.