views:

49

answers:

2

Okay, well supposedly PIL is supposed to be able to work with Tkinter automatically, but mine is not. I found this text file in the Imaging directories Tk directory.

Using PIL With Tkinter 

Starting with 1.0 final (release candidate 2 and later, to be
precise), PIL can attach itself to Tkinter in flight.  As a result,
you no longer need to rebuild the Tkinter extension to be able to
use PIL.

However, if you cannot get the this to work on your platform, you
can do it in the old way:

* Adding Tkinter support

1. Compile Python's _tkinter.c with the WITH_APPINIT and WITH_PIL
   flags set, and link it with tkImaging.c and tkappinit.c.  To
   do this, copy the former to the Modules directory, and edit
   the _tkinter line in Setup (or Setup.in) according to the
   instructions in that file.

   NOTE: if you have an old Python version, the tkappinit.c
   file is not included by default.  If this is the case, you
   will have to add the following lines to tkappinit.c, after
   the MOREBUTTONS stuff:

  {
      extern void TkImaging_Init(Tcl_Interp* interp);
      TkImaging_Init(interp);
  }

   This registers a Tcl command called "PyImagingPhoto", which is
   use to communicate between PIL and Tk's PhotoImage handler.

   You must also change the _tkinter line in Setup (or Setup.in)
   to something like:

   _tkinter _tkinter.c tkImaging.c tkappinit.c -DWITH_APPINIT
  -I/usr/local/include -L/usr/local/lib -ltk8.0 -ltcl8.0 -lX11

Unfortunately I have no idea how to do any of this, and I couldn't find any guides online. Can someone please walk me through how I compile Python's _tkinter.c with the flags set and so on?

A: 

What versions of Python and PIL are you using (and on what platform, etc)? All reasonably recent versions should already support all of these required options (with setup.py as well as Modules/Setup.dict) -- e.g., including tkappinit.c etc -- so it's particularly hard to know what to suggest "in a vacuum". Also, how to compile things (supposing you do need to) can be very platform-dependent, so in case you do need any recompiling (unlikely as that may be), knowing your platform can be important.

Alex Martelli
I'm using Python 2.6.5 and PIL 1.1.7 (the latest PIL) on Mac OS X 10.6. I installed PIL using setup.py, and PIL works except for when I try to use it with Tk.
Dylan
It's weird because I also have a desktop Mac running OS X 10.6 and Python 2.6, and PIL with Tk works fine on that. (The computer it's not working on is a macbook pro). I installed PIL differently on the desktop than I did on the macbook, but unfortunately I don't really remember how I did it.
Dylan
Are you using 2.6.5 on the desktop too, or a different 2.6 such as the one Apple supplies? Maybe that explains it...
Alex Martelli
I'm using 2.6.5 on both.
Dylan
A: 

I'm having this exact same problem, same OS, same versions of Python/PIL. I don't know how to fix it. It's odd, because when I installed PIL, it told me that Tkinter support was available. But when I run selftest.py, it told me tkinter support was not installed. I get segfaults whenever I try to convert an image to a tkinter object.

Tim
So, I found a way around this. Install py26-pil using macports. Solved my problems straight away, I can successfully use PIL with tkinter now.
Tim
cool, I'll try it out.
Dylan