TypeError:“in<string>”需要string作为左操作数,而不是ObjectListView wxPython的int

2024-10-04 03:18:09 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python2.7中使用ObjectListView时,按键盘上的任何字母数字键,我在IDE中收到以下消息error(使用PyCharm):

C:\Users\dylan_cissou\AppData\Local\Continuum\Anaconda\python.exe C:/Users/dylan_cissou/PycharmProjects/SPA/example.py
Traceback (most recent call last):
  File "build\bdist.win-amd64\egg\ObjectListView\ObjectListView.py", line 1410, in _HandleChar
  File "build\bdist.win-amd64\egg\ObjectListView\ObjectListView.py", line 1457, in _HandleTypingEvent
TypeError: 'in <string>' requires string as left operand, not int

我该怎么做才能禁用此消息?我试图找出这两个事件发生的地方,这样我就可以覆盖它们,但是我找不到任何事件。在

代码示例如下:

^{pr2}$

只需按任意键,如“3”、“z”、“x”等。。。每次都会显示红色错误消息。在

谢谢你的帮助。在


Tags: inpybuild消息stringegglinewin
1条回答
网友
1楼 · 发布于 2024-10-04 03:18:09

Hhm似乎是wxPython的一个问题,我在2.8.12unicode build、3.0.2和Phoenix中看到了同样的问题

在evt.GetUnicodeKey应根据Phoenix doc返回字符串: http://wxpython.org/Phoenix/docs/html/KeyEvent.html?highlight=getkeycode#KeyEvent.GetUnicodeKey

根据Robin Dunn的说法,这是不正确的,它应该返回一个int

我在wxPython dev上发布了一个关于这个的问题。在

我将在olv.\u HandleTypingEvent中进行更改,如下所示:

if evt.GetUnicodeKey() == 0:
    uniChar = chr(evt.GetKeyCode())
else:
    uniChar = evt.GetUnicodeKey()
if uniChar not in string.printable:
    return False

收件人:

^{pr2}$

相关问题 更多 >