Tkinter with PIL, Image Corruption - please help

Joel Gould joelg at alum.mit.edu
Mon Mar 12 13:56:57 CET 2001


I have noticed corruption of displayed imaged when using the
PhotoImage object from PIL (Python Image Library) under Tkinter.

I am using Windows 98 SE with 256 MB or RAM.  I see the effect under
Python 2.0 (using the latest Py20 Windows binaries).

I have attached a sample program which fails for me.  The failure
symptom is that the lower 10% of some of the images is corrupted with
noise as you cycle through the images (pressing the button).  Not
every image is corrupted and the corruption pattern changes even when
you get back to the same image.

You can get the images from:

http://www.gouldhome.com/Travel/StThomas00/images/001229_1106_charlotteAmalie1.jpg
http://www.gouldhome.com/Travel/StThomas00/images/001229_1106_charlotteAmalie2.jpg
http://www.gouldhome.com/Travel/StThomas00/images/001229_1106_charlotteAmalie3.jpg
http://www.gouldhome.com/Travel/StThomas00/images/001229_1106_charlotteAmalie4.jpg

Attached is the code sample.  I would appreciate it if anyone could
tell me what is wrong.

----- snip -----


import Tkinter
import Image
import ImageTk

imageList = [
    "001229_1106_charlotteAmalie1.jpg",
    "001229_1106_charlotteAmalie2.jpg",
    "001229_1106_charlotteAmalie3.jpg",
    "001229_1106_charlotteAmalie4.jpg",
    ]

class MainDialog:

    def __init__(self, parent):
        self.canvas = Tkinter.Canvas(parent,width=800,height=600)
        self.canvas.pack()

        self.images = []
        for name in imageList:
            image = Image.open(name)
            image.thumbnail( (800,600) )
            self.images.append(image)

        self.currentImage = 0
        self.tkim = ImageTk.PhotoImage(self.images[self.currentImage])
        self.item = self.canvas.create_image(
            0,0,image=self.tkim,anchor='nw')

        button = Tkinter.Button(parent,
            text='Next Image', command=self.onNewImage)
        button.pack()

    def onNewImage(self):
        self.currentImage = self.currentImage + 1
        if self.currentImage >= len(self.images):
            self.currentImage = 0
        self.tkim = ImageTk.PhotoImage(self.images[self.currentImage])
        self.item = self.canvas.create_image(
            0,0,image=self.tkim,anchor='nw')

if __name__ == '__main__':
    root = Tkinter.Tk()
    dialog = MainDialog(root)
    root.mainloop()




More information about the Python-list mailing list