bind event when typing in TEXTCTRL failure

Hey all.
  I'm having some trouble triggering an event to happen when a person types
in a text control. Really I want to just reset a variable if the user
changes the text in the control, but to test I tried ringing a bell and/or
displaying a messagebox.

I have these (relevent) statements:

in __init__():
    self.text_ctrl_lastName - wx.TextCtrl(self, -1, "")
...
    self.Bind(wx.EVT_CHAR, self.OnKey, self.text_ctrl_lastName)
...
def OnKey(self, event):
    wx.MessageBox("Key!", "Error")

-or-
    print "Key Down"

-or-

   wx.Bell()

I expect every keycap I press while in the Last Name text field should pop a
messagebox, or ring a bell, or print a line in the console window. I don't
see what silly mistake I'm making. Can someone please nudge me?

Thanks!
Dave

GMane Python wrote:

Hey all.
  I'm having some trouble triggering an event to happen when a person types
in a text control. Really I want to just reset a variable if the user
changes the text in the control, but to test I tried ringing a bell and/or
displaying a messagebox.

I have these (relevent) statements:

in __init__():
    self.text_ctrl_lastName - wx.TextCtrl(self, -1, "")
...
    self.Bind(wx.EVT_CHAR, self.OnKey, self.text_ctrl_lastName)

Key and Char events are only sent to the widget with the focus, they don't travel up to parent windows. So you need to bind it like this:

  self.text_ctrl_lastName.Bind(wx.EVT_CHAR, self.OnKey)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!