Custom launcher icon opens a second generic icon

Solution 1:

About Tkinter windows

The window in your image is a Tkinter window. Tkinter windows by default do not match the launcher icon unless you specifically set the launcher (.desktop file) to match the window's WM_CLASS. Further below is explained how to do that.

however

If you do not define a specific WM_CLASS in your python/Tkinter code, all Tkinter windows have the same WM_CLASS. You can see that if you run

xprop WM_CLASS

in a terminal, press Return, and subsequently click on the Tkinter window. This will show:

WM_CLASS(STRING) = "tk", "Tk"

This means that if you possibly have multiple Tkinter applications, they would all appear under the same icon in the launcher. This would be a generic one unless you edit your .desktop file.

How to set a distintive WM_CLASS in python/Tkinter

You can define the WM_CLASS by setting it like below:

#!/usr/bin/env python3
from tkinter import *

# set the WM_CLASS
win = Tk(className="applicationname")
# set the window title
win.wm_title("Test 123")
win.mainloop()

enter image description here

Add the WM_CLASS to your .desktop file

Add the following line to your .desktop file:

StartupWMClass=applicationname

where applicationname is the name you set in the python/Tkinter code.