back next

The ImageTk Module

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

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

Note: If you’re using a prebuilt version of PIL, you might need to install additional packages to be able to use the ImageTk module. For example, on Ubuntu, you need both python-imaging and python-imaging-tk.

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.

Methods #

paste #

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.

Note: Pasting into an RGBA image that is displayed is a very slow operation. It’s usually better to create a new image object.



A Django site. rendered by a django application. hosted by webfaction.