为什么有些字符不能在 Python 的 IDLE 中输入? [英] Why some characters can not be typed in Python's IDLE?

查看:51
本文介绍了为什么有些字符不能在 Python 的 IDLE 中输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何解释,实际上我正在寻找解释,所以我只提一些重现问题的步骤.希望有人能够理解和详细说明:

  1. Windows 8.1 上的 Python 3.5.0.(但是,无论 Python 和 Windows 版本如何,这都应该是可重现的.)
  2. 安装了波斯标准键盘.(它可以从这里下载.我再次'我确定问题不限于这个特定的键盘,其他一些语言中的一些字符也有同样的问题.只是为了可重复性.)
  3. 打开 IDLE,将键盘布局设置为波斯语并输入一些字符.
  4. 对于某些字符,例如 'آ' (Shift+h).它们的打字非常好.
  5. 对于其他一些字符,例如 'ی' (d).它们将转换为类似的字符,在本例中为ي"(注意字形下方的小点).
  6. 有些字符无法输入.例如'﷼' (Shift+4).这些被输入为?"处于空闲状态.
  7. 上述所有字符几乎可以在我安装的任何其他程序中输入.最简单的之一是 notepad.exe.
  8. 我们可以在另一个程序中输入相同的字符,例如notepad.exe 然后将它们复制并粘贴到 IDLE 中.这说明 IDLE 支持 unicode 字符,只是不能输入.

我是 IDLE 的粉丝.它是标准 Python 安装附带的轻量级 IDE,我不想因此而切换到另一个 IDE.但以上对我来说是关于 IDLE 最烦人的事情.每当我需要编写包含一些波斯字符的程序时,我不能相信 IDLE 可以正确键入它们,我必须打开其他程序并使用复制粘贴方法.

我正在寻找的是:

  • 为什么会这样?问题出在哪里?
  • 有什么解决方法吗?
  • 与此问题直接相关的任何文档或错误报告.

此信息也可能有帮助:

<预><代码>>>>导入语言环境>>>locale.getdefaultlocale()('en_US', 'cp1256')>>>locale.getpreferredencoding()'cp1256'>>>locale.getlocale()('English_United States', '1252')>>>>>>导入系统>>>sys.getdefaultencoding()'utf-8'

谢谢.

更新:

请参阅下面的前三个评论.这个问题似乎是由使用 WindowsBestFit 映射 在 tkinter 应用中输入时.

为了测试它是否是在 python/tkinter 绑定或 tcl/tk 本身中的一些错误配置,我下载并安装了 塔卡伯.这是一个用 Tcl/Tk 编写的应用程序.好吧,那里存在完全相同的问题,即我无法输入上述字符,但可以复制和粘贴它们.所以我的结论是,问题的根源在于 tcl/tk 本身,而不是 IDLE/Python/tkinter.

我的问题仍然存在.

解决方案

经过一番搜索,我找到了 thisTk 的错误跟踪器上的票.这几乎解释了幕后发生的事情.TCL/TK 在内部使用代码页将键盘输入转换为 UTF-8.

不幸的是,自 2014 年 9 月 18 日以来,此漏洞没有任何活动,这是一件令人难过的事情.该错误对许多语言都有巨大影响,包括具有 Windows 代码页的语言 (在此处列出),甚至还有许多其他没有任何相关代码页的代码页(例如孟加拉语).

IMO,这应该是 TCL/TK 开发团队的最高优先事项之一.在目前的状态下,用户不应该依赖 Tcl/Tk 来实现 Windows 上需要 Unicode 输入支持的应用程序.

I don't know how to explain this, actually I'm looking for the explanation, so I'll just mention some steps to reproduce the issue. Hopefully someone will be able to understand and elaborate:

  1. Python 3.5.0 on Windows 8.1. (However this should be reproducible regardless of Python and Windows version.)
  2. Having Persian standard keyboard Installed. (It can be downloaded from here. Again I'm sure the problem is not limited to this specific keyboard and there are some characters in some other languages that have the same problem. Just for the sake of reproducibility. )
  3. Open IDLE, set the keyboard's layout to Persian and type some characters.
  4. For some characters like 'آ' (Shift+h). They are typed perfectly fine.
  5. For some other characters like 'ی' (d). They are converted to a similar character, in this case 'ي' (notice the small dots under the glyph).
  6. There are some characters that can't be typed. For example '﷼' (Shift+4). These are typed as '?' in IDLE.
  7. All the above characters can be typed in almost any other program that I have installed. One of the simplest ones being notepad.exe.
  8. We can type the same characters in another program e.g. notepad.exe and then copy and paste them into IDLE. This shows that IDLE supports unicode characters, just can't type them.

I'm a fan of IDLE. It's lightweight IDE that is shipped with the standard Python installation and I don't want to switch to another IDE just because of this. But the above is the most annoying thing about IDLE for me. Whenever I need to write a program with some Persian characters in it, I can't trust IDLE to type them correctly and I have to open some other program and use the copy-paste method.

What I'm looking for is:

  • Why this happens? Where is the problem?
  • Are there any workarounds?
  • Any documentation or bug reports directly related to this issue.

Also this information may be helpful:

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1256')
>>> locale.getpreferredencoding()
'cp1256'
>>> locale.getlocale()
('English_United States', '1252')
>>> 
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

Thanks.

Update:

Please see the first three comments below. It seems that this issue is caused by usage of WindowsBestFit mappings while typing in tkinter apps.

To test whether it's some bad configuration in python/tkinter bindings or tcl/tk itself, I downloaded and installed Tkabber. It's an application written in Tcl/Tk. Well, the exact same problem exists there i.e. I can't type the above characters but can copy and paste them. So my conclusion is that the root of the problem lies in tcl/tk itself and not IDLE/Python/tkinter.

My questions still hold.

解决方案

After some searching I found this ticket on Tk's bug tracker. That pretty much explains what's happening behind the scene. TCL/TK is internally using codepages to translate keyboard input to UTF-8.

Unfortunately there has been no activity around this bug since 2014-09-18 which is a sad thing. The bug has a huge impact on many languages, both those that have a Windows codepage (listed here) and even more on many others that don't have any codepage associated with them (like Bengali).

IMO, this should have been one of the highest priorities of TCL/TK development team. At its current state, users should not rely on Tcl/Tk for applications that require Unicode input support on Windows.

这篇关于为什么有些字符不能在 Python 的 IDLE 中输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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