gpt4 book ai didi

带有部分标题的 Python pywinauto 搜索窗口

转载 作者:行者123 更新时间:2023-11-28 22:45:45 45 4
gpt4 key购买 nike

有没有办法让 pywinauto 找到一个只有部分标题的窗口?

这是我的代码:

import pywinauto

pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'Minitab Professional 5.1 64bit - 3333348.temp.project',
class_name='Window')[0]

问题是每次我打开软件时 temp.project 之前的数字都会改变,因此我无法让 pywinauto 找到正确的窗口。

最佳答案

通过浏览 google code 上的源代码,我看到你可以为标题提供一个正则表达式:

#=========================================================================
def find_windows(class_name = None,
class_name_re = None,
parent = None,
process = None,
title = None,
title_re = None,
top_level_only = True,
visible_only = True,
enabled_only = False,
best_match = None,
handle = None,
ctrl_index = None,
predicate_func = None,
active_only = False,
control_id = None,
):
"""Find windows based on criteria passed in

Possible values are:

* **class_name** Windows with this window class
* **class_name_re** Windows whose class match this regular expression
* **parent** Windows that are children of this
* **process** Windows running in this process
* **title** Windows with this Text
* **title_re** Windows whose Text match this regular expression
* **top_level_only** Top level windows only (default=True)
* **visible_only** Visible windows only (default=True)
* **enabled_only** Enabled windows only (default=True)
* **best_match** Windows with a title similar to this
* **handle** The handle of the window to return
* **ctrl_index** The index of the child window to return
* **active_only** Active windows only (default=False)
* **control_id** Windows with this control id
"""

根据我的说法,pywinauto.findwindows.find_windows(title_re = r'Minitab Professional 5.1 64bit*', class_name='Window')[0] 应该可以工作。

关于带有部分标题的 Python pywinauto 搜索窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28216222/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com