是否可以使用 tkinter 将中文文本输入到 tk Text 和 Entry 小部件中? [英] Is it possible to input Chinese text into tk Text and Entry widgets with tkinter?

查看:50
本文介绍了是否可以使用 tkinter 将中文文本输入到 tk Text 和 Entry 小部件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些带有 tkinter 的 GUI 应用程序,用于处理用户输入的中文文本.我在应用程序中显示中文文本没有问题,当文本粘贴到应用程序中时,我在操作该文本时也没有任何问题,但是当我尝试使用中文输入法将中文文本输入到例如 Text 或 Entry 小部件时,它显示为拉丁字符.这个问题似乎应该有一个微不足道的解决方案(或者它可能不起作用),但我花了很多时间(用英文和中文)寻找答案,但没有找到任何明确的答案.这里出了什么问题?

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?

推荐答案

我在使用 Python 2.7.12 和 Tcl/Tk 8.5.9 的 Mac OS X 10.10 上遇到了这个问题.

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

我通过将 Tcl/Tk 升级到 8.6.6 来修复它(有人说 8.5.18 也可以修复它).可以通过两种方式完成:

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. 如果您使用 Homebrew 安装 Python,请使用它再次安装 Python:brew install python --with-tcl-tk"(可能您需要先卸载它).
  2. 或者您可以从以下位置下载 Python 安装包:http://www.activestate.com/activepython/下载 .
  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 .

顺便说一句,如果您从virtualenv"运行 Python 脚本,即使此环境使用相同版本的 Python 和 Tcl/Tk,您也无法在入口小部件中输入中文.

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.

这篇关于是否可以使用 tkinter 将中文文本输入到 tk Text 和 Entry 小部件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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