display a menu bar icon on osx

Question:

I’d like to have my application display an icon in OSX menu bar (top of screen where Growl sits). How would I do this using Python? (I understand this is not possible using wxPython but I am not after a wxPython specific solution).

Thanks!

Asked By: jldupont

||

Answers:

The API for displaying icons in the OS X menubar is called NSStatusItem. It’s going to be difficult or impossible to use from a wxPython application, though — you will probably have to write your application using PyObjC to use it effectively.

Answered By: user149341

The rumps package makes this very easy. Here’s an example from rumps’s README:

import rumps

class AwesomeStatusBarApp(rumps.App):
    @rumps.clicked("Preferences")
    def prefs(self, _):
        rumps.alert("jk! no preferences available!")

    @rumps.clicked("Silly button")
    def onoff(self, sender):
        sender.state = not sender.state

    @rumps.clicked("Say hi")
    def sayhi(self, _):
        rumps.notification("Awesome title", "amazing subtitle", "hi!!1")

if __name__ == "__main__":
    AwesomeStatusBarApp("Awesome App").run()

rumps example application

Answered By: Brecht Machiels
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.