::: library ::: Python Imaging Library Handbook (2003 Edition)

Back   Next

On this page:
The BitmapImage Class
The PhotoImage Class

The ImageTk Module

The ImageTk module contains support to create and modify Tkinter BitmapImage and PhotoImage objects.

For examples, see the demo programs in the Scripts directory.

The BitmapImage Class

ImageTk.BitmapImage(image, options) => BitmapImage instance

Create a Tkinter-compatible bitmap image, which can be used everywhere Tkinter expects an image object.

The given image must have mode "1". Pixels having value 0 are treated as transparent. Options, if any, are passed to Tkinter. The most commonly used option is foreground, which is used to specify the colour for the non-transparent parts. See the Tkinter documentation for information on how to specify colours.

The PhotoImage Class

ImageTk.PhotoImage(image) => PhotoImage instance

Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object. If the image is an RGBA image, pixels having alpha 0 are treated as transparent.

ImageTk.PhotoImage(mode, size) => PhotoImage instance

Same as above, but creates an empty (transparent) photo image object. Use paste to copy image data to this object.

photo.paste(image, box)

Pastes an image into the photo image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate. If the box is omitted, or None, all of the image is assumed. In all cases, the size of the pasted image must match the size of the region. If the image mode does not match the photo image mode, conversions are automatically applied.

Back   Next