如何在mac上制作一个简单的弹出气球消息。我不想使用NSUserNotification。 使用python-2.7和osx10.8.5。 弹出窗口不应该有任何按钮。弹出窗口应该会自动出现,显示消息并自动离开。它应该和py2app一起正确包装。在
import objc
import Foundation
import AppKit
def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
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)
def notificationBalloon(title,msg):
notify(title1, msg1,"", sound=False)
您可以在AppleScript中使用
display dialog
语句,并使用subprocess
模块的call
函数调用脚本。在它可能看起来有点“黑客化”,但由于您需要一个仅限于Mac的解决方案,我想这是您可以得到的最简单、最轻的解决方案,因为当您将项目打包到
.app
文件中时,您不必使用任何外部库或框架。在相关问题 更多 >
编程相关推荐