KivyMD window 没有显示应用程序的图标。在其他类似问题上尝试了所有其他方式

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

显示默认kivy图标的左上角图标。 earlier image

.py代码

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()

我在与 .py 文件相同的文件中有 stonkss.png。

图片说明。 if this helps!?

好的,它改变了,但仍然不是我想要的图像:top-left

刚刚创建了一个小应用程序: 这样就完美了。

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")

应用图片:enter image description here

这应该适合你

# 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'

我建议使用 ico 作为图标而不是 png,因为当您构建应用程序时 png 将不起作用

更新 你的代码应该是

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")