开发者

How to add Tkinter support for PIL Python library

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 at开发者_JS百科tach 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜