问题
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:
- 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).
- 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