简体   繁体   中英

Python window focus

I would like to find out if a window has focus. I am using pyGTK and would be helpful to us that but have got some Xlib in my script as well.

I've used:

self.window.add_events( gdk.FOCUS_CHANGE_MASK )
self.window.connect("focus-in-event", self.helloworld)

but this gives me the event every time the window is being focused in, even if it is already focused. I want it to tell me just if it isn't focused before.

You can check whether a window is active using the is-active property. Connect to notify::is-active to get a notification when the property value changes.

Example:

def is_active_changed(window, param):
    print window.props.is_active
window.connect('notify::is-active', is_active_changed)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM