TypeError:'in <string>'需要将字符串作为左操作数,而不是ObjectListView wxPython的int

迪伦

在Python 2.7中使用ObjectListView时-按下键盘上的任何字母数字键击,我的IDE(使用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

我应该怎么做才能禁用此消息?我试图找到这两个事件的位置,以便可以覆盖它们,但找不到任何事件。

代码示例为:

import wx
from ObjectListView import ObjectListView, ColumnDefn

########################################################################
class Book(object):
    """
    Model of the Book object

    Contains the following attributes:
    'ISBN', 'Author', 'Manufacturer', 'Title'
    """
    #----------------------------------------------------------------------
    def __init__(self, title, author, isbn, mfg):
        self.isbn = isbn
        self.author = author
        self.mfg = mfg
        self.title = title


########################################################################
class MainPanel(wx.Panel):
    #----------------------------------------------------------------------
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
        self.products = [Book("wxPython in Action", "Robin Dunn",
                              "1932394621", "Manning"),
                         Book("Hello World", "Warren and Carter Sande",
                              "1933988495", "Manning")
                         ]

        self.dataOlv = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.setBooks()

        # Allow the cell values to be edited when double-clicked
        self.dataOlv.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK

        # create an update button
        updateBtn = wx.Button(self, wx.ID_ANY, "Update OLV")
        updateBtn.Bind(wx.EVT_BUTTON, self.updateControl)

        # Create some sizers
        mainSizer = wx.BoxSizer(wx.VERTICAL)        

        mainSizer.Add(self.dataOlv, 1, wx.ALL|wx.EXPAND, 5)
        mainSizer.Add(updateBtn, 0, wx.ALL|wx.CENTER, 5)
        self.SetSizer(mainSizer)

    #----------------------------------------------------------------------
    def updateControl(self, event):
        """

        """
        print "updating..."
        product_dict = [{"title":"Core Python Programming", "author":"Wesley Chun",
                         "isbn":"0132269937", "mfg":"Prentice Hall"},
                        {"title":"Python Programming for the Absolute Beginner",
                         "author":"Michael Dawson", "isbn":"1598631128",
                         "mfg":"Course Technology"},
                        {"title":"Learning Python", "author":"Mark Lutz",
                         "isbn":"0596513984", "mfg":"O'Reilly"}
                        ]
        data = self.products + product_dict
        self.dataOlv.SetObjects(data)

    #----------------------------------------------------------------------
    def setBooks(self, data=None):
        self.dataOlv.SetColumns([
            ColumnDefn("Title", "left", 220, "title"),
            ColumnDefn("Author", "left", 200, "author"),
            ColumnDefn("ISBN", "right", 100, "isbn"),            
            ColumnDefn("Mfg", "left", 180, "mfg")
        ])

        self.dataOlv.SetObjects(self.products)

########################################################################
class MainFrame(wx.Frame):
    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, 
                          title="ObjectListView Demo", size=(800,600))
        panel = MainPanel(self)

########################################################################
class GenApp(wx.App):

    #----------------------------------------------------------------------
    def __init__(self, redirect=False, filename=None):
        wx.App.__init__(self, redirect, filename)

    #----------------------------------------------------------------------
    def OnInit(self):
        # create frame here
        frame = MainFrame()
        frame.Show()
        return True

#----------------------------------------------------------------------
def main():
    """
    Run the demo
    """
    app = GenApp()
    app.MainLoop()

if __name__ == "__main__":
    main()

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

感谢您的帮助。

维尔纳

嗯,似乎是wxPython的问题,我在2.8.12 Unicode版本,3.0.2和Phoenix 2.7以及带OLV 1.3.2的Phoenix上看到了相同的问题

evt.GetUnicodeKey应该根据Phoenix文档返回一个字符串:http ://wxpython.org/Phoenix/docs/html/KeyEvent.html?highlight=getkeycode#KeyEvent.GetUnicodeKey

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

我在wxPython-dev上发布了一个与此有关的问题。

我将对olv._HandleTypingEvent进行如下更改:

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

到:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是int

来自分类Dev

发生异常:TypeError'in <string>'需要将字符串作为左操作数,而不是Series

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是列表

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是QueryDict

来自分类Dev

需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

来自分类Dev

需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

来自分类Dev

如何处理此TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

来自分类Dev

为什么会出现TypeError:'in <string>'需要将字符串作为左操作数,而不是在运行程序时列出错误?

来自分类Dev

在<string>'中需要将字符串作为左操作数,而不是元组

来自分类Dev

遍历字典并获取TypeError:'in <string>'要求将字符串作为左操作数,而不是列表

来自分类Dev

TypeError:'in <字符串>'需要字符串作为左操作数而不是列表

来自分类Dev

我在<string>中获取'需要字符串作为左操作数,而不是元组

来自分类Dev

类型错误:'in <string>' 需要字符串作为左操作数,而不是方法 PYTHON

来自分类Dev

不区分大小写,并且输入age为31时显示错误:TypeError:'in <string>'需要将string作为左操作数

来自分类Dev

为什么键入错误:<string>中的字符串要求字符串作为左操作数,而不是列表

来自分类Dev

Python / Jython:如果字符串中的子字符串总是导致TypeError:字符串成员测试需要char左操作数

来自分类Dev

TypeError:*:'NoneType'和'int'不受支持的操作数类型

来自分类Dev

如何解决错误:“在字符串中”需要字符串作为左操作数而不是元组?

来自分类Dev

逐步完成指向字符串的指针数组-“需要左值作为增量操作数”

来自分类Dev

TypeError:-:'str'和'int'不受支持的操作数类型编写故事吗?

来自分类Dev

TypeError:+不支持的操作数类型:“ int”和“ NoneType”

来自分类Dev

TypeError:%不支持的操作数类型:“ NoneType”和“ int”

来自分类Dev

总和函数prob TypeError:+不支持的操作数类型:'int'和'str'

来自分类Dev

TypeError:+不支持的操作数类型:“ int”和“ Element”

来自分类Dev

Python TypeError:^:“ float”和“ int”的不受支持的操作数类型

来自分类Dev

TypeError:-:“ str”和“ int” Python不支持的操作数类型

来自分类Dev

CuPy和Dirichlet给我TypeError:+ =不受支持的操作数类型:'int'和'tuple'

来自分类Dev

Python:TypeError:+不支持的操作数类型:“ NoneType”和“ int”

Related 相关文章

  1. 1

    TypeError:'in <string>'需要将字符串作为左操作数,而不是int

  2. 2

    发生异常:TypeError'in <string>'需要将字符串作为左操作数,而不是Series

  3. 3

    TypeError:'in <string>'需要将字符串作为左操作数,而不是列表

  4. 4

    TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

  5. 5

    TypeError:'in <string>'需要将字符串作为左操作数,而不是QueryDict

  6. 6

    需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

  7. 7

    需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

  8. 8

    如何处理此TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

  9. 9

    为什么会出现TypeError:'in <string>'需要将字符串作为左操作数,而不是在运行程序时列出错误?

  10. 10

    在<string>'中需要将字符串作为左操作数,而不是元组

  11. 11

    遍历字典并获取TypeError:'in <string>'要求将字符串作为左操作数,而不是列表

  12. 12

    TypeError:'in <字符串>'需要字符串作为左操作数而不是列表

  13. 13

    我在<string>中获取'需要字符串作为左操作数,而不是元组

  14. 14

    类型错误:'in <string>' 需要字符串作为左操作数,而不是方法 PYTHON

  15. 15

    不区分大小写,并且输入age为31时显示错误:TypeError:'in <string>'需要将string作为左操作数

  16. 16

    为什么键入错误:<string>中的字符串要求字符串作为左操作数,而不是列表

  17. 17

    Python / Jython:如果字符串中的子字符串总是导致TypeError:字符串成员测试需要char左操作数

  18. 18

    TypeError:*:'NoneType'和'int'不受支持的操作数类型

  19. 19

    如何解决错误:“在字符串中”需要字符串作为左操作数而不是元组?

  20. 20

    逐步完成指向字符串的指针数组-“需要左值作为增量操作数”

  21. 21

    TypeError:-:'str'和'int'不受支持的操作数类型编写故事吗?

  22. 22

    TypeError:+不支持的操作数类型:“ int”和“ NoneType”

  23. 23

    TypeError:%不支持的操作数类型:“ NoneType”和“ int”

  24. 24

    总和函数prob TypeError:+不支持的操作数类型:'int'和'str'

  25. 25

    TypeError:+不支持的操作数类型:“ int”和“ Element”

  26. 26

    Python TypeError:^:“ float”和“ int”的不受支持的操作数类型

  27. 27

    TypeError:-:“ str”和“ int” Python不支持的操作数类型

  28. 28

    CuPy和Dirichlet给我TypeError:+ =不受支持的操作数类型:'int'和'tuple'

  29. 29

    Python:TypeError:+不支持的操作数类型:“ NoneType”和“ int”

热门标签

归档