wrapper_object()
时间: 2024-04-24 10:21:52 浏览: 20
`wrapper_object()` 方法是 pywinauto 库中的一个方法,它可以将一个控件对象包装成一个 `UIAWrapper` 对象,从而可以使用更多的 UI Automation 功能。
具体来说,当我们使用 pywinauto 库时,可以通过 `child_window()` 或 `window()` 等方法获取到一个控件对象。但是,这个控件对象只能使用 pywinauto 提供的方法和属性,而不能使用更多的 UI Automation 功能。如果想要使用更多的 UI Automation 功能,就可以使用 `wrapper_object()` 方法将控件对象包装成一个 `UIAWrapper` 对象。
例如,如果我们想要使用 UI Automation 功能获取控件的元素名称、元素描述等信息,就可以使用 `wrapper_object()` 方法将控件对象包装成一个 `UIAWrapper` 对象,然后使用 `element_name`、`element_description` 等属性获取更多的信息。
相关问题
pywinauto comobox ._element.wrapper_object() 获取当前选中的item
可以使用`get_selected_item()`函数来获取当前选中的item,示例代码如下:
```python
from pywinauto.controls.win32_controls import ComboBox
# 获取ComboBox对象
combo_box = ComboBox.wrapper_object(class_name="ComboBox", title="ComboBox Title")
# 获取当前选中的item
selected_item = combo_box.get_selected_item()
print(selected_item)
```
其中,`class_name`参数指定了控件类名,`title`参数指定了控件标题。你需要将它们替换为实际的值。
from pywinauto.application import Application from pywinauto.keyboard import send_keys app = Application('win32').connect(class_name_re='class TMainFrame') dlg = app.window(class_name_re='class TMainFrame') #dlg.minimize() #dlg['MouseOrder'].print_control_identifiers() """ dlg['合 约Edit2'].set_edit_text('SHFE AU 2312') dlg['合 约Edit2'].type_keys('{ENTER}') dlg['数 量Edit7'].set_edit_text('5') """ #print(dir(dlg.child_window(best_match='sell').wrapper_object())) #print(dlg['sell'].wrapper_object()) #print(dir(dlg['sell'].wrapper_object())) #print(dlg['sell'].texts()) #print(dlg['sell'].children()) #dlg['sell'].print_control_identifiers() xia_dan = dlg['sell'].rectangle() print(xia_dan)
这段代码中,`dlg['sell'].rectangle()`返回的是一个矩形区域的坐标,表示`sell`控件在窗口客户区域中的位置和大小。具体来说,返回值是一个4元组 `(L, T, R, B)`,其中 `L` 表示矩形左边界的横坐标,`T` 表示矩形上边界的纵坐标,`R` 表示矩形右边界的横坐标,`B` 表示矩形下边界的纵坐标。
你可以通过这个矩形的坐标信息来计算控件的中心坐标或者其他需要的坐标信息。比如,如果你想要获取`sell`控件的中心坐标,可以使用以下代码:
```
x1, y1, x2, y2 = dlg['sell'].rectangle()
center_x = (x1 + x2) // 2
center_y = (y1 + y2) // 2
print("sell控件中心坐标为:({},{})".format(center_x, center_y))
```
这里的 `//` 表示整除运算符,保证计算结果为整数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)