Skip to content

Commit 010bc0b

Browse files
authored
Add files via upload
1 parent ce71e76 commit 010bc0b

2 files changed

Lines changed: 618 additions & 0 deletions

File tree

pack.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import os
2+
import sys
3+
import subprocess
4+
5+
# ================= 配置区域 =================
6+
# 这里填你的源文件名 (必须带 .py)
7+
SOURCE_FILE = "连点器1.0.py"
8+
# 这里填你想生成的 exe 名字
9+
EXE_NAME = "连点器Pro_最终版"
10+
# ===========================================
11+
12+
def install_deps():
13+
"""检查并自动安装必要的打包库"""
14+
print("正在检查环境...")
15+
required = ["pyinstaller", "customtkinter", "pynput"]
16+
for package in required:
17+
try:
18+
__import__(package)
19+
except ImportError:
20+
print(f"正在安装缺失的库: {package}...")
21+
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
22+
23+
def build():
24+
# 0. 检查源文件
25+
if not os.path.exists(SOURCE_FILE):
26+
print(f"\n❌ 错误:找不到文件 [{SOURCE_FILE}]")
27+
print("请确认:\n1. 你的源文件名字真的是 '连点器1.0.py' 吗?\n2. 此脚本是否和源文件在同一个文件夹里?")
28+
return
29+
30+
import PyInstaller.__main__
31+
import customtkinter
32+
33+
# 1. 获取 CustomTkinter 的资源路径 (关键步骤)
34+
ctk_path = os.path.dirname(customtkinter.__file__)
35+
print(f"✅ 找到 UI 库路径: {ctk_path}")
36+
37+
# 2. 组装 PyInstaller 参数
38+
# 注意:Windows下资源分隔符是分号 ;
39+
add_data_arg = f'{ctk_path};customtkinter'
40+
41+
args = [
42+
SOURCE_FILE, # 源文件
43+
f'--name={EXE_NAME}', # exe名字
44+
'--noconfirm', # 覆盖输出不询问
45+
'--onefile', # 打包成单文件 exe
46+
'--windowed', # 【重要】不显示黑色的控制台窗口
47+
'--clean', # 清理临时缓存
48+
f'--add-data={add_data_arg}', # 注入 customtkinter 资源
49+
]
50+
51+
# 如果你有图标,把图标放在同级目录叫 icon.ico,然后取消下面这行的注释
52+
# if os.path.exists("icon.ico"): args.append('--icon=icon.ico')
53+
54+
print(f"\n🚀 开始打包 [{SOURCE_FILE}] ...")
55+
print("这可能需要 1-3 分钟,请耐心等待...\n")
56+
57+
# 3. 执行打包
58+
try:
59+
PyInstaller.__main__.run(args)
60+
print("\n" + "="*40)
61+
print(f"🎉 打包成功!")
62+
print(f"请在生成的 [dist] 文件夹里找:{EXE_NAME}.exe")
63+
print("="*40)
64+
except Exception as e:
65+
print(f"\n❌ 打包出错: {e}")
66+
67+
if __name__ == "__main__":
68+
try:
69+
install_deps()
70+
build()
71+
except Exception as e:
72+
print(f"发生未知错误: {e}")
73+
74+
input("\n按回车键退出...")

0 commit comments

Comments
 (0)