简体   繁体   English

是否可以使用tkinter将中文文本输入到tk Text和Entry小部件中?

[英]Is it possible to input Chinese text into tk Text and Entry widgets with tkinter?

I am working on a few GUI apps with tkinter that manipulate Chinese text inputted by the user. 我正在使用tkinter处理一些GUI应用程序,这些应用程序操纵用户输入的中文文本。 I have no problem displaying Chinese text in the app, nor do I have any problem manipulating that text when it is pasted into the app, but when I try to use a Chinese input method to type Chinese text into, eg, Text or Entry widgets, it shows up as Latin characters instead. 我在应用程序中显示中文文本没有问题,在将文本粘贴到应用程序时也没有任何问题,但是当我尝试使用中文输入法将中文文本输入到文本或条目小部件时,它显示为拉丁字符。 It seems like there should be a trivial solution to this problem (or maybe it just doesn't work), but I have spent a lot of time searching (in English and Chinese) for an answer, without finding anything definitive. 似乎应该有一个简单的解决方案来解决这个问题(或者它可能不起作用),但是我花了很多时间搜索(用中英文)寻找答案,但没有找到任何明确的答案。 What is going wrong here? 这里出了什么问题?

I encountered this problem on Mac OS X 10.10 with Python 2.7.12 and Tcl/Tk 8.5.9. 我在使用Python 2.7.12和Tcl / Tk 8.5.9的Mac OS X 10.10上遇到了这个问题。

And I fixed it by upgrading Tcl/Tk to 8.6.6 (someone stated that 8.5.18 may fix it also). 我通过将Tcl / Tk升级到8.6.6来修复它(有人说8.5.18也可以修复它)。 It could be done by two ways: 它可以通过两种方式完成:

  1. If you use Homebrew to installed Python, use it to install Python again: " brew install python --with-tcl-tk " (may be you need to uninstall it first). 如果您使用Homebrew安装Python,请使用它再次安装Python:“ brew install python --with-tcl-tk ”(可能需要先卸载它)。
  2. Or you may download the Python installation package from: http://www.activestate.com/activepython/downloads . 或者您可以从以下网址下载Python安装包: http//www.activestate.com/activepython/downloads

BTW, you are not able to input Chinese in the entry widget if you run the Python script from a "virtualenv" even this environment use the same verion of Python and Tcl/Tk. 顺便说一下,如果你从“virtualenv”运行Python脚本,你就无法在条目小部件中输入中文,即使这个环境使用相同的Python和Tcl / Tk版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM