python 菜单栏编写_如何在Python中制作OSX的菜单栏(系统任务栏)应用程序?

After having spent quite some time looking at ways to an app for the menu bar we're close to admit defeat.

We are basically just looking for an example/pointer on how to create an app that will put itself in the menu bar (the small icons next to the clock), and have a menu. Nothing fancy at all.

It feels like something that should be very easy to do, but we haven't been able to find an example that works.

Maybe it's not possible with Python? Does anyone know how others do it?

解决方案

An option would be to use rumps which provides a level of abstraction on top of PyObjC. I wrote it specifically for quickly generating these types of simple status bar apps.

I hope that this could help a few people out there looking for a simple, semantic solution!

A short example snippet follows. Decorators are used for registering functions as callbacks for click events and timers. There is also support for 10.8 notifications.

import rumps

class AwesomeStatusBarApp(rumps.App):

def __init__(self):

super(AwesomeStatusBarApp, self).__init__("Awesome App")

self.menu = ["Preferences", "Silly button", "Say hi"]

@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().run()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值