如何访问pywinauto.controls.hwndrapper.rectangle中左上方的值?

问题描述 投票:0回答:1

在pywinauto.rectangle()上,我获得了set_focus()在窗口屏幕上的位置,在client_rect()上,我获得了该窗口的尺寸。

我想获取屏幕上窗口位置的左侧和顶部以及窗口大小的宽度和高度。

我设法通过其他函数获得宽度和高度:W = pywinauto.win32structures.RECT.width(client_rect)H = pywinauto.win32structures.RECT.height(client_rect)

但是我无法访问左侧和顶部。


app = controls.hwndwrapper.HwndWrapper(title)
rect = app.rectangle()
# print out
rect (L1293, T6, R1851, B1026)
rect type <class 'pywinauto.win32structures.RECT'>


app = controls.hwndwrapper.HwndWrapper(title)
client_rect = app.client_rect()
# print out
client_rect (L0, T0, R558, B1020)
client_rect type <class 'pywinauto.win32structures.RECT'>


# I cant access like this either:
values = []
app = controls.hwndwrapper.HwndWrapper(title)
rect = app.rect()
values.append(rect)
# print out
values [<RECT L1293, T6, R1851, B1026>]
values type <class 'list'>

# I try this too:
x = values[0]
# prints out:
x (L1293, T6, R1851, B1026)

x = values[1]
# prints out
x = values[1]
IndexError: list index out of range


python-3.x pywinauto
1个回答
0
投票

client_rect对象只有简单的属性:

print(client_rect.left, client_rect.top, client_rect.right, client_rect.bottom)

还有另外一种获取矩形中心点的方法:

print(client_rect.mid_point())

高度和宽度也是方法:

print(client_rect.width())
print(client_rect.height())
© www.soinside.com 2019 - 2024. All rights reserved.