Python
import tkinter as tk
import pyautogui
import time
def search_position():
x1, y1 = pyautogui.position()
position_label.config(text=f"您当前位置坐标为: x:{x1} y:{y1}")
# 获取宽度和高度
time.sleep(1)
x2, y2 = pyautogui.position()
width = abs(x2 - x1)
height = abs(y2 - y1)
width_label.config(text=f"宽度: {width}")
height_label.config(text=f"高度: {height}")
def start_search():
info_label.config(text="请将鼠标移动到您想要确定宽度和高度的区域的左上角并记录下该位置的坐标。")
search_button.config(state=tk.DISABLED)
root.after(1000, search_position)
def reset_search():
position_label.config(text="您当前位置坐标为: ")
width_label.config(text="宽度: ")
height_label.config(text="高度: ")
search_button.config(state=tk.NORMAL)
root = tk.Tk()
root.title("位置搜索")
root.geometry("500x250")
info_label = tk.Label(root, text="请按下开始按钮开始搜索位置")
info_label.pack(pady=10)
position_label = tk.Label(root, text="您当前位置坐标为: ")
position_label.pack()
width_label = tk.Label(root, text="宽度: ")
width_label.pack()
height_label = tk.Label(root, text="高度: ")
height_label.pack()
search_button = tk.Button(root, text="开始", command=start_search)
search_button.pack(pady=10)
reset_button = tk.Button(root, text="重新获取", command=reset_search)
reset_button.pack(pady=5)
root.mainloop()