开发者

display a menu bar icon on osx

开发者 https://www.devze.com 2023-03-26 13:48 出处:网络
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

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!


An implementation of this may be found at:

https://web.archive.org/web/20080709014939/http://the.taoofmac.com/space/blog/2007/04/22/1745

http://the.taoofmac.com/space/blog/2007/04/22/1745


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.


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

display a menu bar icon on osx

0

精彩评论

暂无评论...
验证码 换一张
取 消