In other excellent answers I hear complaints about the lousy non-color icons in xbm for linux. But the original question does not specify the operating system.
For Linux the answer seems today, as of december 2023, that you don't need an icon file in your app anymore, whether color or xbm. The reason is that, on windows, while some apps still show an icon in the app title bar, such as Gimp, KeePass, DBeaver, a lot of apps do not, like: command terminal, Firefox, File Explorer, Google Chrome.
On Linux, such as Ubuntu and Raspberry Pi, these apps, in fact all apps that I checked today, do NOT show the icon in the application title bar. These apps do show the app icon in the system task bar, as specified in the app.desktop file, hence the app does not need to be programmed in the app itself, as described in the other answers here.
It seems that the icon in the app title bar is getting out of fashion, and that Windows lags behind Linux in this respect. The reason seems that in this way application real estate (screen space) is used more efficiently. Modern apps show instead the icons of the file or site that is open in the respective tabs of the app.
This all might be the reason that I could not get the other answers to work for my linux python app.
TLDR: for Linux, this question does not need any application code, same for modern Windows apps.
.ico
file will not work for this(at least on linux). Try using a.xbm
or.xpm
file instead. – Extramundane