fix icon not packed within EXE file

This commit is contained in:
Zichao Lin 2024-06-22 22:27:54 +08:00
parent 594e3e87fe
commit 69f320ec2d
Signed by: earthjasonlin
GPG Key ID: 406D9913DE2E42FB
2 changed files with 74 additions and 2 deletions

65
auto-py-to-exe.json Normal file

@ -0,0 +1,65 @@
{
"version": "auto-py-to-exe-configuration_v1",
"pyinstallerOptions": [
{
"optionDest": "noconfirm",
"value": true
},
{
"optionDest": "filenames",
"value": "J:/Projects/LuckyDraw/main.py"
},
{
"optionDest": "onefile",
"value": true
},
{
"optionDest": "console",
"value": false
},
{
"optionDest": "icon_file",
"value": "J:/Projects/LuckyDraw/icon.ico"
},
{
"optionDest": "clean_build",
"value": false
},
{
"optionDest": "strip",
"value": false
},
{
"optionDest": "noupx",
"value": false
},
{
"optionDest": "disable_windowed_traceback",
"value": false
},
{
"optionDest": "uac_admin",
"value": false
},
{
"optionDest": "uac_uiaccess",
"value": false
},
{
"optionDest": "argv_emulation",
"value": false
},
{
"optionDest": "bootloader_ignore_signals",
"value": false
},
{
"optionDest": "datas",
"value": "J:/Projects/LuckyDraw/icon.png;."
}
],
"nonPyinstallerOptions": {
"increaseRecursionLimit": true,
"manualArguments": ""
}
}

11
main.py

@ -4,6 +4,8 @@ import random
import winreg import winreg
from datetime import datetime from datetime import datetime
import os import os
import pkg_resources
import base64
# 注册表路径 # 注册表路径
REGISTRY_PATH = r"Software\StudentIDDraw" REGISTRY_PATH = r"Software\StudentIDDraw"
@ -305,18 +307,23 @@ def close_settings_window():
settings_window.destroy() settings_window.destroy()
settings_window = None settings_window = None
def get_icon_data():
icon_path = pkg_resources.resource_filename(__name__, 'icon.png')
with open(icon_path, 'rb') as icon_file:
return base64.b64encode(icon_file.read())
# 初始化全局变量 # 初始化全局变量
selected_ids = load_selected_ids() selected_ids = load_selected_ids()
settings_window = None settings_window = None
history_list = None history_list = None
icon_data = get_icon_data()
# 创建主窗口 # 创建主窗口
root = tk.Tk() root = tk.Tk()
root.title("随机抽号机") root.title("随机抽号机")
root.attributes("-topmost", 1) root.attributes("-topmost", 1)
icon_path = os.path.join("icon.png") icon_image = tk.PhotoImage(data=icon_data)
icon_image = tk.PhotoImage(file=icon_path)
root.iconphoto(True, icon_image) root.iconphoto(True, icon_image)
# 创建标签,用于显示抽取的学号 # 创建标签,用于显示抽取的学号