在 windows 任务栏中显示 png(或 ico)作为图标

Display a png (or ico) as icon in the windows taskbar

我有一张图片,我想让我的 python 程序(tkinter GUI)将其可视化为 Windows 任务栏中的图标,我该怎么做?

icon = tk.PhotoImage(file="icon.png")
root.iconphoto(True, icon)

请注意,这仅处理 2 个图标位置中的 1 个,文件的图标需要在 windows 资源管理器中设置。

我认为当文件是 .py 时你不能这样做。它需要是一个可执行文件。

https://www.geeksforgeeks.org/convert-python-script-to-exe-file/

打开任何终端(如 cmd、WT 或 PS)并与其他 pyinstaller 标志一起添加 --icon="path_to_icon.ico"

示例:

pyinstaller my_program.py --icon="icon.ico"