首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSUserNotificationCenter.defaultUserNotificationCenter()在python中返回None

NSUserNotificationCenter.defaultUserNotificationCenter()在python中返回None
EN

Stack Overflow用户
提问于 2013-04-16 01:35:28
回答 1查看 1.2K关注 0票数 6

我正在尝试通过python连接到Mountain Lion通知中心。我已经安装了pyobjc,并且正在遵循herehere的说明。另请参阅:Working with Mountain Lion's Notification Center using PyObjC

下面是我的代码:

代码语言:javascript
复制
import Foundation, objc
import AppKit
import sys

NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')

def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
    """ Python method to show a desktop notification on Mountain Lion. Where:
        title: Title of notification
        subtitle: Subtitle of notification
        info_text: Informative text of notification
        delay: Delay (in seconds) before showing the notification
        sound: Play the default notification sound
        userInfo: a dictionary that can be used to handle clicks in your
                  app's applicationDidFinishLaunching:aNotification method
    """
    notification = NSUserNotification.alloc().init()
    notification.setTitle_(title)
    notification.setSubtitle_(subtitle)
    notification.setInformativeText_(info_text)
    notification.setUserInfo_(userInfo)
    if sound:
        notification.setSoundName_("NSUserNotificationDefaultSoundName")
    notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
    NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)

当我调用带有参数的notify函数时,我得到一个属性错误:

AttributeError: 'NoneType' object has no attribute 'scheduleNotification_'

我不明白为什么NSUserNotificationCenter.defaultUserNotificationCenter()要返回一个NoneType对象。我还没能在互联网上对这件事提出任何疑问。

EN

回答 1

Stack Overflow用户

发布于 2013-04-16 04:03:52

因此,使用Ned的建议使用默认python可以很好地工作。当我将pyobjc安装在32位的installed发行版上时,它也能正常工作。在我看来,pyobjc只适用于32位的python发行版(我不能证实这一点,但到目前为止似乎是这样的)。

(注意:当我发布这个问题时,我已经将pyobjc安装到了64位的installed发行版上)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16021330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档