tray_icon.py
561 Bytes
import pystray
from PIL import Image, ImageDraw
import threading
def create_image(width, height, color1, color2):
image = Image.new("RGB", (width, height), color1)
dc = ImageDraw.Draw(image)
dc.rectangle((width // 2, 0, width, height // 2), fill=color2)
return image
def run_icon(icon_path):
image = Image.open(icon_path) # 加载自定义图标
icon = pystray.Icon("test_icon", image, "My System Tray Icon")
icon.run()
def start_tray_icon(icon_path):
threading.Thread(target=run_icon, args=(icon_path,), daemon=True).start()