【问题标题】:How to add Tkinter support for PIL Python library如何为 PIL Python 库添加 Tkinter 支持
【发布时间】:2011-03-13 03:12:59
【问题描述】:

好吧,据说 PIL 应该能够自动与 Tkinter 一起工作,但我的不是。我在成像目录 Tk 目录中找到了这个文本文件。

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 吗?

【问题讨论】:

    标签: python compilation python-imaging-library tkinter


    【解决方案1】:

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

    【讨论】:

    • 我在 Mac OS X 10.6 上使用 Python 2.6.5 和 PIL 1.1.7(最新的 PIL)。我使用 setup.py 安装了 PIL,并且 PIL 可以正常工作,除非我尝试将它与 Tk 一起使用。
    • 这很奇怪,因为我还有一台运行 OS X 10.6 和 Python 2.6 的桌面 Mac,而带有 Tk 的 PIL 可以正常工作。 (它不工作的计算机是 macbook pro)。我在桌面上安装 PIL 的方式与在 macbook 上安装的方式不同,但不幸的是我真的不记得我是怎么做到的了。
    • 您是在桌面上使用 2.6.5,还是使用 Apple 提供的其他 2.6?也许这可以解释它......
    猜你喜欢
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    相关资源
    最近更新 更多