[Image-SIG] PhotoImage Class

Fredrik Lundh fredrik at pythonware.com
Thu Apr 6 15:17:59 CEST 2006

Eric Germaneau wrote:

> I wish to ise the photimage class and I'm wondering wether someone would
> have an example ....

the basics are really simple:

    import ImageTk

    photo = ImageTk.PhotoImage(file="somefilename")


    im = ... some image operation ...

    photo = ImageTk.PhotoImage(im)

The resulting object can be used everywhere you can use a Tkinter.PhotoImage



    label = Label(image=photo)

here's a complete example:

    import sys
    import Image, ImageTk, Tkinter

    root = Tkinter.Tk()

    im = Image.open(sys.argv[1])
    im.thumbnail((400, 400))

    photo = ImageTk.PhotoImage(im)

    label = Tkinter.Label(root, image=photo)

    # see note on http://effbot.org/tkinterbook/photoimage.htm
    label.image = photo


the above script loads the image given as an argument, resizes it to 400x400 (max),
and displays it in a Tkinter label widget.

hope this helps!


More information about the Image-SIG mailing list