TextCtrl focus events in wxWidgets

Frank Millman frank at chagford.com
Wed Jul 19 08:41:24 EDT 2006


Simon Hibbs wrote:
> Frank Millman wrote:
>
> > Try self.PlantCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl)
>
> And Voila! It works. Many, many thanks.
>

My pleasure

> Any idea what is going on?

I only understand it in simple terms, though it can get complex. Here
is my simple explanation.

Events are received by objects. There are default event handlers that
are called to deal with the events. If you want your own event handler
to be called, you use Bind(), which brings together three elements -
the window receiving the event (in wxPython, all objects derive from
wx.Window), the event itself, and the event handler to be called.

In pseudo code, you call Bind() like this -

    w = the window receiving the event
    e = the event
    h = the handler to be called

    w.Bind(e,h)

You bound EVT_KILL_FOCUS to self, which I assume in your case is a
panel, but the panel does not receive the KILL_FOCUS event, the text
control does.

For more information, type help(wx.Window.Bind) at the interpreter
prompt.

If you want an authoritative answer, post a question to the wxPython
mailing list. Robin Dunn, the creator of wxPython and the resident
guru, is always happy to explain in detail exactly what is going on.
You can also get Robin's book, wxPython In Action.

Frank




More information about the Python-list mailing list