Search code examples
pythonwxpythonrichtextctrl

wxPython - RichTextCtrl Event Handling


For testing purposes, I'm trying to print in the console everything that I write in a RichTextCtrl. However, it isn't working. Here is the way I wrote the binding for the RichTextCtrl, called textArea:

self.textArea.Bind( wx.EVT_KEY_DOWN, self.syntaxColoring_C )

And here is the event handler:

def syntaxColoring_C( self, event ):
    print self.textArea.GetValue()

However, when I type something, only a blank line is printed in the console, and nothing appears written in the RichTextCtrl. What am I doing wrong? Thanks in advance.


Solution

  • This can be corrected by adding event.Skip() in your event handling.

    def syntaxColoring_C(self,event):
        print self.textArea.GetValue()
        event.Skip()
    

    Quoting from This link,

    You’ll notice that I also call “event.Skip” at the end. Iif you don’t call Skip, then the key will “eaten” and there won’t be a corresponding char event. This won’t matter on a button, but you might care in a text control as char events are the proper way of catching upper and lower case, accents, umlauts and the like.