[Image-SIG] ImageTk bug
Nick Bower
bowern@ses.curtin.edu.au
Thu, 03 Aug 2000 04:31:42 GMT
--------------=_4D4800BBE4640871F1F0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I think I've figured out how to use the palette, but I may have found a =
bug in the PhotoImage class of ImageTk. If the marked line in the short=
=20
testcode (attached) isn't commented out, the program segfaults as you'll=
=20
see by running it.
Anyone know how else to make palettes work with Tk?
nick
--------------=_4D4800BBE4640871F1F0
Content-Description: filename="piltest.py"
Content-Disposition: inline; filename="piltest.py"
Content-Type: text/plain; name ="piltest.py"
Content-Transfer-Encoding: quoted-printable
#!/usr/bin/python
from Tkinter import *
import Image, ImageTk
class piltest(Frame):
def __init__(self, toplevel):
# GUI Setup
Frame.__init__(self,toplevel)
self.photoimage =3D ImageTk.PhotoImage('P',(300,300))
imagecanvas =3D Canvas(self, width=3D300,height=3D300)
imagecanvas.pack(side=3DBOTTOM)
imagecanvas.create_image(150,150,image=3Dself.photoimage)
def putdata(self,data):
im =3D Image.new('P', (300,300))
im.putdata(data)
palette =3D [0] * 3 * 256
palette[0 :14 ] =3D [0, 0, 0, 200,0, 255,0, 187,127,219,1=
12,163,171,230,127]
palette[0+256:14+256] =3D [0, 0, 0, 200,0, 255,0, 187,127,219,1=
12,163,171,230,127]
palette[0+512:14+512] =3D [0, 0, 255,0, 255,255,115,0, 127,147,2=
19,255,127,0, 127]
#
# IF THE FOLLOWING LINE IS UNCOMMENTED, A SEGAULT OCCURS AFTER
# THE PHOTOIMAGE PASTE METHOD
#
im.putpalette(palette)
print 'trying to paste'
self.photoimage.paste(im)
print 'done pasting - no more code'
# Run as script
if (__name__ =3D=3D '__main__'):
toplevel =3D Tk()
atest =3D piltest(toplevel)
atest.pack()
atest.putdata([0,1]*45000) # simulate 300x300 image
atest.mainloop()
--------------=_4D4800BBE4640871F1F0--