How to manually invoke wxPython event
<p>I have a <code>textCTRL</code> (Wxpython) with event binding to it:</p>

<pre><code>self.x= wx.TextCtrl(self, -1, "")
self.x.Bind(wx.EVT_KILL_FOCUS, self.OnLeavex)
</code></pre>

<p>I want to manually trigger this event as I wish.
I read this topic: <a href="http://stackoverflow.com/questions/747781/wxpython-calling-an-event-manually">wxPython: Calling an event manually</a> but nothing works.</p>

<p>I tried:</p>

<pre><code>wx.PostEvent(self.x.GetEventHandler(), wx.EVT_KILL_FOCUS)
</code></pre>

<p>But it gives:</p>

<blockquote>
  <p>TypeError: in method 'PostEvent', expected argument 2 of type 'wxEvent
  &amp;'</p>
</blockquote>

<p>I also tried:</p>

<pre><code>self.x.GetEventHandler().ProcessEvent(wx.EVT_KILL_FOCUS)
</code></pre>

<p>Which doesn't work as well.</p>

<p>The things like <code>wx.EVT_KILL_FOCUS</code> are not the event object needed here.  Those are instances of <code>wx.PyEventBinder</code> which, as the name suggests, are used to bind events to handlers.  The event object needed for the <code>PostEvent</code> or <code>ProcessEvent</code> functions will be the same type of object as what is received by the event handler functions.  In this case it would be an instance of <code>wx.FocusEvent</code>.  </p>

<p>When creating the event object you may also need to set the event type if that event class is used with more than one type of event.  The binder object has that value to help you know what to use.  You usually also need to set the ID to the ID of the window where the event originated.  So for your example, it would be done something like this:</p>

<pre><code>evt = wx.FocusEvent(wx.EVT_KILL_FOCUS.evtType, self.x.GetId())
wx.PostEvent(self.x.GetEventHandler(), evt)
</code></pre>

<p>...or...</p>

<pre><code>self.x.GetEventHandler().ProcessEvent(wx.EVT_KILL_FOCUS)
</code></pre>

python wxpython