如何在Python中制作OSX的菜单栏(系统任务栏)应用程序? [英] How to make an menu bar (system tray) app for OSX in Python?

查看:261
本文介绍了如何在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.

也许使用Python无法实现?有谁知道别人是怎么做的?

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

推荐答案

一种选择是使用 rumps ,它在PyObjC之上提供了一个抽象级别.我专门为快速生成这些类型的简单状态栏应用而编写.

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!

下面是一个简短的示例代码段.装饰器用于将功能注册为单击事件和计时器的回调.还支持10.8通知.

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

这篇关于如何在Python中制作OSX的菜单栏(系统任务栏)应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆