1
Showing
7 changed files
with
65 additions
and
1 deletions
.gitignore
0 → 100644
app.ico
0 → 100644
No preview for this file type
eee
deleted
100644 → 0
| 1 | r'r'rv | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
exe/we.exe
0 → 100644
This file is too large to display.
readme.md
0 → 100644
| 1 | ## | ||
| 2 | 重要文件就是这个了 | ||
| 3 | |||
| 4 | ## | ||
| 5 | tray_icon.py 是来进行显示系统托盘图标的 | ||
| 6 | |||
| 7 | ## | ||
| 8 | 主函数 we.py | ||
| 9 | 使用了 注释和引用图标逻辑 | ||
| 10 | # -*- coding: utf-8 -*-- | ||
| 11 | import asyncio | ||
| 12 | import websockets | ||
| 13 | from bleak import BleakScanner, BleakClient | ||
| 14 | import json | ||
| 15 | import base64 | ||
| 16 | import threading | ||
| 17 | from tray_icon import start_tray_icon | ||
| 18 | start_tray_icon("app.ico") | ||
| 19 | ## 打包需要python3 然后 | ||
| 20 | 使用 pip cache dir 观察python3 的路径 | ||
| 21 | |||
| 22 | 安装环境 | ||
| 23 | ## | ||
| 24 | pip install pyinstaller | ||
| 25 | pip install bleak | ||
| 26 | pip install pystray pillow | ||
| 27 | |||
| 28 | ## | ||
| 29 | 打包指令 产生一个带窗口的程序 打包完后可以随便改exe 名字 | ||
| 30 | C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\Scripts\pyinstaller.exe --onefile --icon=data\app.ico we.py --add-data "data;data" | ||
| 31 | |||
| 32 | ## | ||
| 33 | 端口占用 | ||
| 34 | netstat -ano | findstr :201111 | ||
| 35 | taskkill /PID /F 1234 | ||
| 36 | |||
| 37 | ## | ||
| 38 | app.ico 需要有特定格式 不能随便图片 | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | ## | ||
| 43 | 运行时的路径 和打包后的路径 是不一致的 如何解决 见具体函数 | ||
| 44 | |||
| 45 | icon_path = resource_path(resource_path("data/app.ico")) |
tray_icon.py
0 → 100644
| 1 | import pystray | ||
| 2 | from PIL import Image, ImageDraw | ||
| 3 | import threading | ||
| 4 | |||
| 5 | def create_image(width, height, color1, color2): | ||
| 6 | image = Image.new("RGB", (width, height), color1) | ||
| 7 | dc = ImageDraw.Draw(image) | ||
| 8 | dc.rectangle((width // 2, 0, width, height // 2), fill=color2) | ||
| 9 | return image | ||
| 10 | |||
| 11 | def run_icon(icon_path): | ||
| 12 | image = Image.open(icon_path) # 加载自定义图标 | ||
| 13 | icon = pystray.Icon("test_icon", image, "My System Tray Icon") | ||
| 14 | icon.run() | ||
| 15 | |||
| 16 | def start_tray_icon(icon_path): | ||
| 17 | threading.Thread(target=run_icon, args=(icon_path,), daemon=True).start() | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
we.py
0 → 100644
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment