[Pythonmac-SIG] PIL gui with Panther python?
Kevin Altis
altis at semi-retired.com
Sun Jul 11 17:27:10 CEST 2004
On Jul 10, 2004, at 9:50 PM, David Eppstein wrote:
> I have a Wapplication app that I'm trying to port to something that
> runs
> under the Panther command-line python. It needs to be able to display
> PIL Images. Is this possible under Cocoa with PyObjC or am I stuck
> with
> ugly Tkinter?
>
I'm sure PyObjC will work, but I'm guessing you'll have to do an image
conversion from PIL using the convert and tostring methods. Someone has
probably already written this routine, I'm just not familiar enough
with PyObjC to tell you where to look.
In PythonCard, which uses wxPython, I have the following utility
routines in the graphic.py module to handle the conversion to wx.Image
and wx.Bitmap from PIL.
def PILToImage(pilImage):
if (pilImage.mode != 'RGB'):
pilImage = pilImage.convert('RGB')
imageData = pilImage.tostring('raw', 'RGB')
img = wx.EmptyImage(pilImage.size[0], pilImage.size[1])
img.SetData(imageData)
return img
def PILToBitmap(image):
return wx.BitmapFromImage(PILToImage(image))
<plug>
As you might guess, wxPython and PythonCard run fine on Mac OS X and
can easily display PIL images, in fact PythonCard has a built-in
drawBitmap method for the BitmapCanvas component that handles PIL
automatically as well as Numeric arrays. There are also pictureViewer
and slideshow samples included with PythonCard in case you don't want
to right any code at all.
</plug>
So, no you don't have to use Tkinter <wink>
ka
More information about the Pythonmac-SIG
mailing list