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

1.3k views Asked by At

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?

2

There are 2 answers

1
falsetru On BEST ANSWER

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()
0
ntg On

Complementary to the previous answer, here is one that works for any EVT... I had a similar problem, and took some time to find the exact name of the event. Checking the source code, the file wx\core.py has most of the conversions, in my case:

EVT_LISTBOX_DCLICK = wx.PyEventBinder( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, 1)

In your case it is in the file wx\_controls.py:

EVT_TEXT_ENTER  = wx.PyEventBinder( wxEVT_COMMAND_TEXT_ENTER, 1)