wol
wol

Reputation: 424

binding one widget to EVT_TEXT event to trigger more than one event handlers in wxpython

In my example entering of some data to wx.TextCtrl widget must trigger two event handler function. but first binding is overridden by last binding.

self.tc_limit.Bind(wx.EVT_TEXT, self.calculate_registration_fee)
self.tc_limit.Bind(wx.EVT_TEXT, self.catch_errors)

In my situation when exception occurs last binding works but after entering correct data to widget it does not trigger first binding

So how i can do it

Upvotes: 0

Views: 306

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22433

Use event.Skip() like so:

import wx
def onText1(event):
    print "First Text1!"
    event.Skip()

def onText2(event):
    print "Then Text2!"

app = wx.App()

frame = wx.Frame(None, -1, '')
box = wx.StaticBox(frame, -1, "")
sizer = wx.StaticBoxSizer(box, orient=wx.VERTICAL)
text0 = wx.StaticText(frame,label="1st Item")
text0_input = wx.TextCtrl(frame, wx.ID_ANY, size=(345,25))
text0_input.SetValue("")
sizer.Add(text0, wx.ALIGN_LEFT|wx.ALL, border=10)
sizer.Add(text0_input, wx.ALIGN_LEFT|wx.ALL, border=10)
text0_input.Bind(wx.EVT_TEXT, onText2)
text0_input.Bind(wx.EVT_TEXT, onText1)

main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(sizer)
frame.SetSizer(main_sizer)

frame.Centre()
frame.Show()
text0_input.SetFocus()
window_focus = True

app.MainLoop()

event.Skip()
"This method can be used inside an event handler to control whether further event handlers bound to this event will be called after the current one returns. Without Skip() (or equivalently if Skip(False) is used), the event will not be processed any more. If Skip(True) is called, the event processing system continues searching for a further handler function for this event, even though it has been processed already in the current handler."

Upvotes: 1

Related Questions