04 Working with Images#

Using PhotoImage tkinter and ttk work with gif, pgm or ppm images and use xbm with BitmapImage. (PhotoImage and BitmapImage are both imported using tkinter).

Display Images in tkinter#

tkinter version

PhotoImage

BitmapImage

all versions

gif

xbm

all versions

pgm

all versions

ppm

8.6 or higher

png

You can check out the tkinter version as follows:

import tkinter
print(tkinter.TkVersion)

Some widgets have a property option called image (it is shown in Tkinter 8.5 reference: a GUI for Python) so once the image file is initiated in PhotoImage it can be loaded directly onto the widget.

Note

All the images used with the examples will be found in the directory "images". and the programs can be run using the same directory structure on your computer.