PySimpleGUI+PyInstaller生成EXE任务栏图标重合问题咨询
PySimpleGUI打包EXE任务栏图标共享问题解决方案
这是PySimpleGUI从4.58.0版本开始引入的已知问题,根源在于新版本中Windows平台的默认应用程序ID(App User Model ID)被统一设置,导致系统任务栏将不同名称的打包EXE识别为同一应用,进而共享图标。
临时解决办法
1. 手动设置唯一应用程序ID
在创建窗口前,通过Windows API为每个程序指定唯一的AppUserModelID,确保系统能区分不同应用。修改后的代码如下:
import PySimpleGUI as sg import ctypes # 为每个程序设置唯一的ID,格式自定义即可 myappid = 'my.unique.app.id.v1' ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) layout = [[sg.T(f"PSG version: {sg.version}")]] window = sg.Window('Taskbar icon issue', layout) while True: event, values = window.read() if event == sg.WINDOW_CLOSED: break window.close()
重新用pyinstaller --onefile --noconsole main.py --icon icon.ico打包后,不同名称的EXE将在任务栏显示各自的图标。
2. 降级PySimpleGUI版本
如果暂时不想修改代码,可以降级到4.57.0版本,该版本不存在此问题:
pip install PySimpleGUI==4.57.0
不过此方法会错过后续版本的功能更新与Bug修复,仅作为临时过渡方案。
内容的提问来源于stack exchange,提问作者Lee-xp
相关产品推荐
相关产品推荐

