58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""
|
|
图标捕获工具
|
|
用于捕获微信、小程序图标、一见星球等图标
|
|
"""
|
|
import pyautogui
|
|
import time
|
|
from pathlib import Path
|
|
|
|
|
|
def capture_icon(icon_name: str, delay: int = 5):
|
|
"""
|
|
捕获图标
|
|
1. 运行此函数
|
|
2. 在延迟时间内将鼠标移动到目标图标上
|
|
3. 程序会自动截图保存
|
|
"""
|
|
template_dir = Path(__file__).parent / "images"
|
|
template_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
print(f"请在 {delay} 秒内将鼠标移动到要捕获的图标上...")
|
|
time.sleep(delay)
|
|
|
|
x, y = pyautogui.position()
|
|
print(f"当前鼠标位置:({x}, {y})")
|
|
|
|
screenshot = pyautogui.screenshot(region=(x-30, y-30, 60, 60))
|
|
filepath = template_dir / f"{icon_name}.png"
|
|
screenshot.save(str(filepath))
|
|
print(f"图标已保存到:{filepath}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("=== 微信图标捕获工具 ===\n")
|
|
|
|
while True:
|
|
print("\n请选择要捕获的图标:")
|
|
print("1. 桌面微信图标 (wechat_icon)")
|
|
print("2. 小程序图标 (miniprogram_icon)")
|
|
print("3. 一见星球小程序 (yijian_planet_icon)")
|
|
print("4. 手动指定名称")
|
|
print("0. 退出")
|
|
|
|
choice = input("\n选择:")
|
|
|
|
if choice == "0":
|
|
break
|
|
elif choice == "1":
|
|
capture_icon("wechat_icon", delay=5)
|
|
elif choice == "2":
|
|
capture_icon("miniprogram_icon", delay=5)
|
|
elif choice == "3":
|
|
capture_icon("yijian_planet_icon", delay=5)
|
|
elif choice == "4":
|
|
name = input("输入图标名称(不带扩展名): ")
|
|
capture_icon(name, delay=5)
|
|
else:
|
|
print("无效选择,请重试")
|