There are three general methods for displaying graphic images in your Tkinter application.
To display bitmap (two-color) images in the
.xbm format, refer to Section 5.9.1, “The
To display full-color images in the
format, see Section 5.9.2, “The
The Python Imaging Library (PIL) supports images in a
much wider variety of formats. Its
ImageTk class is specifically designed for
displaying images within Tkinter applications. See
the author's companion document for PIL
documentation: Python Imaging Library
(PIL) quick reference.
To display a two-color image in the
format, you will need this constructor:
the name of the
.xbm image file.
Normally, foreground (1) bits in the image will be
displayed as black pixels, and background (0) bits in
the image will be transparent. To change this
behavior, use the optional
option to set the background to color
, and the
foreground= option to set the foreground to color
. For color
specification, see Section 5.3, “Colors”.
This constructor returns a value that can be used
anywhere Tkinter expects an image. For example, to
display an image as a label, use a
widget (see Section 12, “The
Label widget”) and supply the
BitmapImage object as the value of the
logo = tk.BitmapImage('logo.xbm', foreground='red') Label(image=logo).grid()