【发布时间】:2015-02-11 18:15:13
【问题描述】:
我想用 pygobject 在通知中显示一个按钮。这个按钮在点击时应该会调用回调,但它没有,我不明白为什么。
这是我的代码:
from gi.repository import Notify, Gtk
class Test:
def __init__(self):
Notify.init('example')
self.notif()
Gtk.main()
def notif(self):
notif = Notify.Notification.new('Title', 'something','dialog-information')
notif.add_action('display', 'Button', self.callback, None)
notif.show()
def callback(self, notif_object, action_name, users_data):
print("Work!")
Gtk.main_quit()
Test()
当我点击按钮“按钮”时,什么也没有发生,回调也没有被调用。 有什么问题?
经过一些尝试,我发现当我将Gtk.main() 紧跟在notif.show() 之后时,回调起作用了。但是我不能使用这个解决方案,因为这意味着我以后不能显示其他通知。
【问题讨论】:
标签: python notifications pygobject