在Python和OS X中使用臀部而不创建类 [英] Using Rumps in Python and OS X Without Creating a Class

查看:68
本文介绍了在Python和OS X中使用臀部而不创建类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个问题,该问题解释了如何在OS X上使用朗姆酒在Python中创建系统菜单.它基本上取自 rumps文档,而我看到它几乎用在任何地方的朗姆酒上.

I found this question that explains how to use rumps on OS X to create a system menu in Python. It's basically taken from the rumps documentation and I've seen it used almost any place rumps is demonstrated.

我意识到,如果我使用rumps,则必须将其用作对象,但是是否有可能仅在代码中创建适当的rumps对象,而无需创建自己的额外类来使用它?

I realize that if I use rumps, I'll have to use it as an object, but is it possible to just create the appropriate rumps object in my code without creating an extra class of my own to use it?

如果不是,是否有一个原因必须在另一个对象中使用隆起,并且在不创建包装类的情况下不能使用隆起?

If not, is there a reason rumps must be used within another object and can't be used without creating what amounts to a wrapper class?

是否有任何示例(或任何人都可以提供示例),说明如何使用rumps创建系统菜单,包括在程序中调用函数,而不使用rumps直接需要的OOP以外的任何OOP?

Are there any examples (or can anyone provide an example) of how to use rumps to create a system menu, including having calls to a function in a program, without using any OOP other than what's required directly by rumps?

推荐答案

您在寻找什么?

您可以直接创建rumps.App的实例,然后将非成员函数装饰为@rumps.click()以使其运行.基本上:

You can create an instance of rumps.App directly, then decorate your non-member functions as @rumps.click() to get them to run. Basically:

@rumps.clicked("About")
def about(sender):
    rumps.alert("This is a cool app!")

@rumps.clicked("Preferences")
def about(sender):
    rumps.alert("This is a cool app's settings!")

app = rumps.App("My Toolbar App", title='World, Hello')
app.menu = [
    rumps.MenuItem('About', icon='pony.jpg', dimensions=(18, 18)), 
    'Preferences',
]
app.run()

这篇关于在Python和OS X中使用臀部而不创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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