As mentioned earlier, Python tkinter scripts show images by associating independently
created image objects with real widget objects. At this writing,
tkinter GUIs can display photo image files in GIF, PPM, and PGM
formats by creating a
object, as well as X11-style bitmap files (usually suffixed with an
.xbm extension) by creating a
This set of supported file formats is limited by the underlying Tk library, not by tkinter itself, and may expand in the future (it has not in many years). But if you want to display files in other formats today (e.g., the popular JPEG format), you can either convert your files to one of the supported formats with an image-processing program or install the PIL Python extension package mentioned at the start of Chapter 7.
PIL, the Python Imaging Library, is an open source system that supports nearly 30 graphics file formats (including GIF, JPEG, TIFF, PNG, and BMP). In addition to allowing your scripts to display a much wider variety of image types than standard tkinter, PIL also provides tools for image processing, including geometric transforms, thumbnail creation, format conversions, and much more.
To use its tools, you must first fetch and install the PIL package: see
(or search for “PIL” on the web). Then, simply use special
BitmapImage objects imported from the PIL
ImageTk module to open files in other graphic formats. These are ...