如何添加Tkinter支持PIL Python库 [英] How to add Tkinter support for PIL Python library

查看:334
本文介绍了如何添加Tkinter支持PIL Python库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


不幸的是,我不知道如何做到这一点,我找不到任何指南在线。有人可以告诉我如何编译Python的_tkinter.c的标志设置等等。

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?

推荐答案

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

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.

这篇关于如何添加Tkinter支持PIL Python库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆