“findbestmatch”模块是如何工作的?

2024-06-26 00:29:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解findbestmatch模块是如何工作的。这里有一个例子。在

from pywinauto.application import Application
from pywinauto.findbestmatch import find_best_match
ditto=Application().connect(path='Ditto.exe').window(title="Ditto",class_name="QPasteClass")
ditto.ditto.ListView.findbestmatch.find_best_match(hello)

我试图使用它的一个方法来获取HELLO 2中列出的HELLO 2项。(这些项没有自己的控件标识符)

print(ditto.print_control_identifiers())给出:

^{pr2}$

我尝试了ditto.ListView.findbestmatch.find_best_match("HELLO 2")和其他许多没有用的方法。在


Tags: 模块方法fromimporthelloapplicationmatchditto
1条回答
网友
1楼 · 发布于 2024-06-26 00:29:49

findbestmatch是一个非常低级的模块,因此通常在调用属性访问时隐式使用它(比如app.Ditto和{}是等价的)。但在您的例子中,显式地使用findbestmatch是必要的。下面是一个例子:

from pywinauto import findbestmatch
texts = ditto.ditto.ListView.texts()[1:] # skip window text itself, use only item texts
items = ditto.ditto.ListView.items()

found_item = findbestmatch.find_best_match('pasted', texts, items)
print(found_item)

相关问题 更多 >