This module is for use with the graphical user interface functions of the Tkinter package. For more information about the Tkinter widget set, see the local Tkinter page.
To import the ImageTk module:
import ImageTk
This module contains two class constructors:
ImageTk.BitmapImage(i,**options)
Given an image , constructs a
iBitMapImage object that can be
used wherever Tkinter expects an image object. The
image must have mode "1". Any keyword
are passed on to Tkinter. For example, the option
optionsforeground= can be used to display the pixels of value
1 in color c, while pixels of value 0 are
transparent.
c
ImageTk.PhotoImage(i)
Given an image , constructs a iPhotoImage
object that can be used wherever Tkinter expects an
image object.
There is a bug in the current version of the Python
Imaging Library that can cause your images not to
display properly. When you create an object of
class PhotoImage, the reference
count for that object does not get properly
incremented, so unless you keep a reference to that
object somewhere else, the
PhotoImage object may be
garbage-collected, leaving your graphic blank on
the application.
For example, if you have a canvas or label widget
that refers to such an image object, keep a list
named .imageList in that object,
and append all PhotoImage
objects to it as they are created. If your widget
may cycle through a large number of images, you
will also want to delete the objects from this list
when they are no longer in use.
ImageTk.PhotoImage(mode, size)
Creates an empty PhotoImage
object with the given mode and
size.
To change image data in a
PhotoImage object, use this method:
.paste(i2, bbox=None)
Image data from an Image object
is
pasted into the i2PhotoImage object.
To paste the new data into a given location, specify
the
argument as a bounding box; this
argument can be omitted if bbox is the same size as the
i2PhotoImage object.