wxPython 整个窗口焦点事件 [英] wxPython Whole Window Focus Event

查看:34
本文介绍了wxPython 整个窗口焦点事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用wxPython,当整个窗口进入/离开焦点时如何触发事件?

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

详细说明,我正在构建一个串行终端 GUI,并且希望在用户没有选择我的应用程序时关闭连接,并在用户将我的应用程序带回前台时重新打开连接.我的应用程序只是从 wx.Frame 派生的单个窗口.

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.

推荐答案

这种情况的正确答案是使用绑定到框架的 EVT_ACTIVATE 处理程序.每当框架被激活(相对于当前打开的其他窗口进入前台)或停用时,都会有一个事件.您可以使用事件对象的 GetActive 方法来判断刚刚发生了什么.

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.

这篇关于wxPython 整个窗口焦点事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆