How to set an application's name?

My app while run from source shows <filename>.py. How can I avoid it and set a proper name? I tried this GLib.set_application_name but it didn’t work. Do I have to use Desktop files to do that, or shall I change my filename from <filename>.py to <appname>?

Minimal working example
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gtk

class App(Gtk.Application):
    
    def __init__(self):
        
        super().__init__(application_id="org.me.my_app")
        self.win = Gtk.Window(title="Hi")
        self.win.add(Gtk.Label(label="Look at the app name at the panel"))
    
    def do_startup(self):
        
        Gtk.Application.do_startup(self)
        GLib.set_application_name("MyApp")
        self.win.set_application(self)
        self.win.show_all()
    
    def do_activate(self):
        
        Gtk.Application.do_activate(self)

app = App()
app.run()
1 Like