windows 获取 Python 中打开的窗口列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2022219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:42:44  来源:igfitidea点击:

Get list of open windows in Python

pythonwindowspywin32

提问by masterLoki

I am writing an app in Python that must be able to send keys or text to another app. For example, if I have Firefox open, I should be able to send it an URL to open it.

我正在用 Python 编写一个应用程序,它必须能够将密钥或文本发送到另一个应用程序。例如,如果我打开了 Firefox,我应该可以向它发送一个 URL 来打开它。

I already have the SendKeys module, and I have read about the win32 module too, but I do not know if there is a way to filter out process without open windows.

我已经有了 SendKeys 模块,我也读过 win32 模块,但我不知道是否有办法在不打开窗口的情况下过滤掉进程。

回答by Peter Hansen

Usually, for this sort of "GUI automation" pyWinAutois a good way to go. We use it to allow automated testing of GUI applications, and it ought to let you "type" URLs into Firefox (not to mention finding its window) as well.

通常,对于这种“GUI 自动化”,pyWinAuto是一个不错的选择。我们使用它来允许对 GUI 应用程序进行自动化测试,它也应该让您在 Firefox 中“键入”URL(更不用说找到它的窗口了)。

回答by reckoner

try using dragonfly. It has a whole lot of automation stuff built into it. You don't need the speech recognition part in order to use the automation stuff. For example:

尝试使用蜻蜓。它内置了很多自动化的东西。你不需要语音识别部分来使用自动化的东西。例如:

from dragonfly import Window
Window.get_all_windows()

will return a list of all the windows.

将返回所有窗口的列表。

you also want to look at the FocusWindow()and Keys()objects in dragonfly.

您还想查看蜻蜓中的FocusWindow()Keys()对象。

回答by Isaiah

Even if you need to use automation for everything else your app is going to do, it would probably be a lot easier to use the webbrowsermodule for opening urls in the user's browser.

即使您需要对应用程序将要执行的所有其他操作使用自动化,使用该webbrowser模块在用户浏览器中打开 url可能会容易得多。