import time
import threading
import tkinter as tk
import pyautogui as pag
import sys
def update():
try:
while True:
# 获取屏幕的尺寸
screenWidth, screenHeight = pag.size()
x, y = pag.position()
# 返回鼠标的坐标
print("\r", end="")
print('屏幕尺寸: (%s, %s), 鼠标坐标 : (%s, %s)' % (screenWidth, screenHeight, x, y), end="")
label1['text'] = str('屏幕尺寸: (%s, %s), 鼠标坐标 : (%s, %s)' % (screenWidth, screenHeight, x, y)) #显示内容
sys.stdout.flush()
# 每个0.001s打印一次
time.sleep(0.001)
except KeyboardInterrupt:
print('结束')
root = tk.Tk()
root.title("鼠标坐标获取")
label1 = tk.Label(root, text='0', width=50)
label1.pack()
update_thread = threading.Thread(target=update)
update_thread.start()
root.mainloop()
鼠标坐标获取
于 2024-01-28 17:06:46 首次发布
