wxPython Whole Window Focus Event

那年仲夏 提交于 2019-12-13 00:06:37

问题


With wxPython, how does one trigger an event whenever the whole window goes into/out of focus?

To elaborate, I'm building a serial terminal GUI and would like to close down the connection whenever the user doesn't have my application selected, and re-open the connection whenever the user brings my app back into the foreground. My application is just a single window derived from wx.Frame.


回答1:


The correct answer for this case is to use an EVT_ACTIVATE handler bound to the frame. There will be an event whenever the frame is activated (brought into the foreground relative to other windows currently open) or deactivated. You can use the event object's GetActive method to tell which just happened.




回答2:


as WxPerl programmer i know there is

EVT_SET_FOCUS(

EVT_KILL_FOCUS(

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




回答3:


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

Gist of it: wx.EVT_KILL_FOCUS works fine, but wx.EVT_SET_FOCUS behaves a little oddly for any panel containing widgets (the child's set-focus prevents the panel's set-focus event from firing as expected?)




回答4:


In addition to what these fellows are saying, you might also want to try EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW. I think these are fired when you move the mouse into and out of the frame widget, although I don't think the frame has to be in focus for those events to fire.

@ Hugh - thanks for the readership!



来源:https://stackoverflow.com/questions/4505097/wxpython-whole-window-focus-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!