在Python中打印出来的坐标太多,如何把所有打印出来的坐标保存到记事本里
时间: 2024-03-02 18:50:45 浏览: 15
你可以使用Python中的文件操作来保存打印出来的坐标到记事本里。具体操作如下:
1. 使用Python中的open函数打开一个文件,可以指定文件名和打开方式(写入模式):
```
f = open('coordinates.txt', 'w')
```
2. 将打印出来的坐标写入到文件中,可以使用print函数并指定文件对象(即第一个参数):
```
print(coordinates, file=f)
```
3. 关闭文件:
```
f.close()
```
完整代码示例:
```
coordinates = [(0, 0), (1, 1), (2, 2)]
f = open('coordinates.txt', 'w')
for coord in coordinates:
print(coord, file=f)
f.close()
```
这样,打印出来的坐标就会保存到名为coordinates.txt的记事本中。
相关问题
python pywinauto 坐标
Python pywinauto 可以使用坐标来控制 Windows 应用程序的操作。坐标可以指定窗口、控件或者屏幕上的位置。下面是一个示例代码,使用 pywinauto 模块获取记事本程序中编辑框的坐标,并将光标移动到该编辑框中:
```python
import pywinauto
# 运行记事本程序
app = pywinauto.Application().start('notepad.exe')
# 获取编辑框的句柄和坐标
dlg = app.top_window()
edit = dlg.child_window(class_name='Edit')
left, top, right, bottom = edit.rectangle()
# 将光标移动到编辑框中
edit.click_input(coords=(10, 10))
```
在上述代码中,`edit.rectangle()` 返回编辑框的左上角和右下角坐标,`edit.click_input(coords=(10, 10))` 将光标移动到编辑框的左上角。你可以根据实际应用场景,使用不同的坐标来控制 Windows 应用程序的操作。
python获取窗口句柄某个组件坐标
可以使用 Python 的 win32gui 模块来获取窗口句柄,然后使用 win32gui 模块的 GetWindowRect 函数来获取窗口的坐标。如果要获取窗口中某个组件的坐标,需要先获取该组件的句柄,然后使用 GetWindowRect 函数来获取该组件在窗口中的坐标。
以下是一个示例代码,可以获取 Windows 记事本中编辑框的坐标:
```python
import win32gui
# 获取窗口句柄
hwnd = win32gui.FindWindow(None, "无标题 - 记事本")
# 获取编辑框句柄
edit_hwnd = win32gui.FindWindowEx(hwnd, 0, "Edit", None)
# 获取编辑框坐标
left, top, right, bottom = win32gui.GetWindowRect(edit_hwnd)
print("编辑框坐标:", left, top, right, bottom)
```
在上面的示例代码中,我们首先使用 win32gui 模块的 FindWindow 函数来获取 Windows 记事本的窗口句柄。然后使用 FindWindowEx 函数来获取编辑框的句柄。最后使用 GetWindowRect 函数来获取编辑框在窗口中的坐标,并将坐标打印出来。
相关推荐
![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)