KivyMD window is not showing the icon of the app. Tried every other way on other similar questions

The top-left icon which shows the default kivy icon. earlier image

.py code

class StonkkApp(MDApp):
    
    def build(self):
        self.icon = f'{cur_file_path}/stonkss.png'
        screen = Builder.load_file('layout.kv')
        self.theme_cls.theme_style = theme
        self.theme_cls.primary_palette = 'Gray'
        return screen

    
    def restart(self):
        self.root.clear_widgets()
        self.stop()
        return StonkkApp().run()

I have stonkss.png in the same file as that of the .py file.

Image desc. if this helps!?

Ok, it changed but still not the image i want: top-left

Just created a small app: In this way it works perfectly.

from kivy.config import Config
import os
from pathlib import Path

cur_file_path = os.path.dirname(os.path.abspath(__file__)).replace('\','/')
Config.set('kivy', 'window_icon', f'{cur_file_path}/stonkss.ico')

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel

class MainApp(MDApp):
    icon = f'{cur_file_path}/stonkss.ico'

    def build(self):
        return MDLabel(text="Hello, World", halign="center")

App image: enter image description here

Answer

this should works for you

# add this at the top of your code
from kivy.config import Config

Config.set('kivy', 'window_icon', f'{cur_file_path}/stonkss.png')
# in your app class
class StonkkApp(MDApp):
    icon = f'{cur_file_path}/stonkss.png'

I recommended to use ico as an icon not png because the png will not work when you build the app

Update your code should be

from kivy.config import Config
cur_file_path = os.path.dirname(os.path.abspath(__file__)).replace('\','/')
Config.set('kivy', 'window_icon', f'{cur_file_path}/stonkss.png')



from kivymd.app import MDApp
from kivymd.uix.label import MDLabel

import os
from pathlib import Path



class MainApp(MDApp):
    icon = f'{cur_file_path}/stonkss.png'

    def build(self):
        return MDLabel(text="Hello, World", halign="center")