首页 > 解决方案 > 打开文件时如何在pyinstaller中添加自己的图标

问题描述

当我通过 pyinstaller 将我的 python 文件编译为 exe 时。我在想有没有办法在打开文件时添加自己的自定义图标。

就像我打开文件时看到的一样:

带圆圈的是我在任务栏上的 Tkinter 应用程序图标

当我打开我的应用程序时,圈出的是 Tkinter 徽标

那么如何解决这个问题。我想添加自己的徽标

标签: pythontkinterpyinstaller

解决方案


在您的应用程序代码中,添加以下内容:

root.iconbitmap("path_to_icon.ico")

whereroot是分配给的变量,Tk()path_to_icon.ico存储图标的路径。

.

使用 pyinstaller 时,添加标志--icon="path_to_icon.ico"

例子: pyinstaller my_program.py --icon="icon.ico"


推荐阅读