pythonwxpythonassertionstextctrl

wxPython TextCtrl assertion error: wx.wxEVT_COMMAND_TEXT_ENTER not a PyEventBinder instance


Trying to make a wxPython TextCtrl to react on ENTER, I get an assertion error:

self.fileNameInput = wx.TextCtrl (self, style=wx.TE_PROCESS_ENTER)
self.fileNameInput.Bind (wx.wxEVT_COMMAND_TEXT_ENTER, self.onRename)

terminates with an assertion error in Bind:

assert isinstance(event, wx.PyEventBinder)
AssertionError

No wonder that wx.wxEVT_COMMAND_TEXT_ENTER is not an instance, it's number.

I read a remark about changes to the events between Python 2 and 3 - did I mix versions of libraries?


Solution

  • Do you mean wx.EVT_TEXT_ENTER ?

    >>> import wx
    >>> wx.wxEVT_COMMAND_TEXT_ENTER
    10165
    >>> wx.EVT_TEXT_ENTER
    <wx._core.PyEventBinder object at 0x000000000321C8D0>
    

    Example:

    import wx
    
    class MyWindow(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None)
            self.fileNameInput = wx.TextCtrl (self, style=wx.TE_PROCESS_ENTER)
            self.fileNameInput.Bind(wx.EVT_TEXT_ENTER, self.onRename)
        def onRename(self, e):
            print('ENTER')
    
    app =wx.PySimpleApp()
    win = MyWindow()
    win.Show()
    app.MainLoop()