b0685f53 by huangyf2

init

0 parents
dist
build
__pycache__
\ No newline at end of file
No preview for this file type
No preview for this file type
This file is too large to display.
##
重要文件就是这个了
##
tray_icon.py 是来进行显示系统托盘图标的
##
主函数 we.py
使用了 注释和引用图标逻辑
# -*- coding: utf-8 -*--
import asyncio
import websockets
from bleak import BleakScanner, BleakClient
import json
import base64
import threading
from tray_icon import start_tray_icon
start_tray_icon("app.ico")
## 打包需要python3 然后
使用 pip cache dir 观察python3 的路径
安装环境
##
pip install pyinstaller
pip install bleak
pip install pystray pillow
##
打包指令 产生一个带窗口的程序 打包完后可以随便改exe 名字
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"
##
端口占用
netstat -ano | findstr :201111
taskkill /PID /F 1234
##
app.ico 需要有特定格式 不能随便图片
##
运行时的路径 和打包后的路径 是不一致的 如何解决 见具体函数
icon_path = resource_path(resource_path("data/app.ico"))
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()
\ No newline at end of file
This diff is collapsed. Click to expand it.
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!