WxPython background event event

Using wxPython, how is an event triggered whenever a whole window goes to / from focus?

To develop, I create a serial terminal GUI and would like to close the connection when the user does not have my application, and reopen the connection whenever the user brings my application back to the forefront. My application is just one window derived from wx.Frame.

+1
source share
4 answers

The correct answer for this case is to use the EVT_ACTIVATE handler associated with the frame. An event will occur whenever a frame is activated (brought to the fore with respect to other currently open windows) or deactivated. You can use the GetActive method of the event object to report what just happened.

+4
source

as a WxPerl programmer, I know that there is

EVT_SET_FOCUS (

EVT_KILL_FOCUS (

if you trigger this event by listening to the frame as the first parameter, it should work like in Perl, since the API is almost the same

+2
source

http://www.blog.pythonlibrary.org/2009/08/27/wxpython-learning-to-focus/

: wx.EVT_KILL_FOCUS , wx.EVT_SET_FOCUS , ( set-focus, ?)

+2
source

In addition to what these guys are saying, you can also try EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW. I think they fire when you move the mouse in and out of the frame widget, although I don’t think the frame needs to be in focus for these events to shoot.

@ Hugh - thanks to the readers!

+2
source

All Articles