python 窗体取数_使用Python获取活动窗口

这是一个用Python编写的脚本,可以在Linux、Windows和Mac上运行,用于获取当前活跃窗口的名称。在Linux中,它使用wnck库;在Windows中,依赖win32gui;在Mac上,依赖AppKit。脚本首先检查系统的平台,然后根据平台导入相应的库来获取活跃窗口的信息。
摘要由CSDN通过智能技术生成

以下脚本应该可以在Linux、Windows和Mac上运行。它目前只在Linux上测试(UbuntuMateUbuntu15.10)。

先决条件

对于Linux:

在Ubuntu上安装wnck(sudo apt-get install python-wnck,请参阅libwnck)

对于Windows:

确保win32gui可用

对于Mac:

确保AppKit可用

剧本#!/usr/bin/env python

"""Find the currently active window."""

import logging

import sys

logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',

level=logging.DEBUG,

stream=sys.stdout)

def get_active_window():

"""

Get the currently active window.

Returns

-------

string :

Name of the currently active window.

"""

import sys

active_window_name = None

if sys.platform in ['linux', 'linux2']:

# Alternatives: http://unix.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值