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!
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.
An implementation of this may be found at:
https://web.archive.org/web/20080709014939/http://the.taoofmac.com/space/blog/2007/04/22/1745
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()
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!
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.
An implementation of this may be found at:
https://web.archive.org/web/20080709014939/http://the.taoofmac.com/space/blog/2007/04/22/1745
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()