You can, but it involves X calls from what I know. I don't know how you do it in Python, though. If you have xprop installed, you can invoke "xprop -root" and look at the _NET_ACTIVE_WINDOW or _MB_CURRENT_APP_WINDOW. The numbers represent a Window ID (XID). You can use them to get the WMCLASS or the title of an application