python获取屏幕截图区域坐标

上述答题助手中许多朋友不知道该如何获取屏幕截图区域信息,我写了一个比较简单的思路,大家可供参考。代码如下:

import pyautogui
import time

def find_area():
    print("请将鼠标移动到可能包含第一个数字的区域的左上角,然后按下回车键。")
    input()
    top_left = pyautogui.position()
    print(f"左上角坐标:{top_left}")

    print("请将鼠标移动到可能包含第一个数字的区域的右下角,然后按下回车键。")
    input()
    bottom_right = pyautogui.position()
    print(f"右下角坐标:{bottom_right}")

    width = bottom_right[0] - top_left[0]
    height = bottom_right[1] - top_left[1]

    return top_left[0], top_left[1], width, height

print("开始确定第一个数字的截图区域。")
first_area = find_area()

print("开始确定第二个数字的截图区域。")
second_area = find_area()

print(f"第一个数字截图区域:{first_area}")
print(f"第二个数字截图区域:{second_area}")

这个代码会提示你逐步移动鼠标确定截图区域的左上角和右下角坐标,然后计算出截图区域的宽度和高度,并返回这个区域的参数。可以根据这个区域参数进行后续的数字识别和比较操作。

猜你喜欢

转载自blog.csdn.net/m0_69482013/article/details/142828424