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

一个人想着一个人 提交于 2021-02-07 04:10:35

问题


I am working on a few GUI apps with tkinter that manipulate Chinese text inputted by the user. 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, e.g., 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?


回答1:


I encountered this problem on Mac OS X 10.10 with Python 2.7.12 and Tcl/Tk 8.5.9.

And I fixed it by upgrading Tcl/Tk to 8.6.6 (someone stated that 8.5.18 may fix it also). 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).
  2. Or you may download the Python installation package from: 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.



来源:https://stackoverflow.com/questions/28747976/is-it-possible-to-input-chinese-text-into-tk-text-and-entry-widgets-with-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!