2010-07-08 83 views
2

好吧,据说PIL应该能够自动与Tkinter一起工作,但我的不是。我在映像目录Tk目录中找到了这个文本文件。如何添加Tkinter支持PIL Python库

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 

不幸的是我不知道如何做任何的这个,我不能在网上找到任何指南。有人可以请我通过如何编译Python的_tkinter.c和设置标志等吗?

回答

0

您正在使用哪些版本的Python和PIL(以及在什么平台等)?所有合理的最新版本应该已经支持所有这些必需的选项(setup.py以及Modules/Setup.dict) - 例如,包括tkappinit.c等 - 因此很难知道在真空中建议什么”。另外,如何编译东西(假设您需要)可能会非常依赖于平台,所以如果您确实需要重新编译(不太可能如此),那么了解您的平台可能很重要。

+0

我在Mac OS X 10.6上使用Python 2.6.5和PIL 1.1.7(最新的PIL)。我使用setup.py安装了PIL,除了当我尝试将它与Tk一起使用时,PIL工作。 – Dylan 2010-07-08 14:55:12

+0

这很奇怪,因为我也有一台运行OS X 10.6和Python 2.6的台式机Mac,而带Tk的PIL在这方面效果很好。 (它不在使用的计算机是MacBook Pro)。我在桌面上安装PIL的方式与我在MacBook上的方式不同,但不幸的是,我不记得我是如何做到的。 – Dylan 2010-07-08 16:28:11

+0

您是否也在桌面上使用2.6.5,或者使用不同的2.6,例如Apple提供的2.6?也许这可以解释它... – 2010-07-08 17:14:02