Search code examples
pythonmacoswxpythonpy2apppyobjc

Mac OS Quit Application menu label same as python script name


When I run my wxPython app in Mac OS X, the "Quit" menu item under the Application menu has the label "Quit Myapp", where myapp.py is the name of the main python script. If I rename it to, for example, coolapp.py, the label on the menu item becomes "Quit Coolapp".

Even when I package the application using py2app, although the Application menu changes from 'Python' to the name specified in my setup.py, the Quit menu item remains the same.

How can I change this menu item to use a different application name? Is there any way to use the pyobjc bridge with wxPython?


Solution

  • As it turns out, PyObjC is not required, and this can be done from wxPython only.

    The function to call is SetAppName(name), but this must be done from the OnInit(self): method. Previously I was calling this function after the App instance had been created, and it did nothing.

    Your code should look like this:

    class MyApp(wx.App):
        def OnInit(self):
            # Set application name before anything else
            self.SetAppName("My App Name")
            mainframe = MyMainFrame(None, wx.ID_ANY, "")
            self.SetTopWindow(mainframe)
            mainframe.Show()
            return 1
    
    if __name__ == '__main__':
        myapp = MyApp()
        myapp.MainLoop()