| 123456789101112131415161718192021222324252627282930313233 |
- # -*- coding: utf-8 -*-
- import pyautogui
- import tkinter as tk
- def update_position():
- x, y = pyautogui.position()
- screen_width, screen_height = pyautogui.size()
- x_percent = (x / screen_width) * 100
- y_percent = (y / screen_height) * 100
- label.config(text=f"X: {x_percent:.2f}%\nY: {y_percent:.2f}%")
- root.after(100, update_position) # 每100毫秒更新一次
- # 创建主窗口
- root = tk.Tk()
- root.title("鼠标位置")
- # 设置窗口大小(稍微大一点)
- root.geometry("160x80") # 宽度200像素,高度100像素
- # 设置字体大小(稍微大一点)
- font_style = ("Arial", 14) # 使用Arial字体,字号12
- # 创建一个标签用于显示鼠标位置百分比
- label = tk.Label(root, text="等待中...", font=font_style)
- label.pack(pady=10) # 垂直方向上留出10像素的间距
- # 启动更新位置的函数
- update_position()
- # 运行主循环
- root.mainloop()
|