Intercepting wx.EVT_TEXT for multiple TextCtrls

7stud bbxx789_05ss at yahoo.com
Mon Apr 23 04:20:22 PDT 2007


> Should I be simply binding the wx.EVT_TEXT to a function which does
> the calculation? Like this:
> 
> self.Bind(wx.EVT_TEXT,self.DoSomeCalcAndUpdate)
> 
> I'm assuming I don't have to bind this event for each TextCtrl on the
> panel.  Also, is there a better way to capture events from
> modifications to one of those text controls?

If it works the same way as having a few buttons in a panel, which 
seems like a reasonable assumption, then when you omit a source as 
the 3rd argument in the call to Bind(), the specified object(e.g. self)
is notified of the specified event no matter which widget it comes 
from--so it acts as a catch all, and the event handler will execute.

On the other hand, if you specify a source as the 3rd 
argument to Bind()--for instance the variable name of a specific
TextCtrl--then that event handler will only fire when the event occurs
on that widget.  Also, if there is a catch all binding as well, like this:

self.Bind(wx.EVT_TEXT,self.DoSomeCalcAndUpdate)
self.Bind(wx.EVT_TEXT, self.SpecialCalc, textCtrlA)

The binding with the source specified will override the catch all.










More information about the wxpython-users mailing list