gpt4 book ai didi

python - Gtk 通知不显示持有 '<' 的正文

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:54 25 4
gpt4 key购买 nike

我正在尝试在 python 中使用 pygobject(版本 3.16)的通知模块显示通知。我的代码运行良好,除非有 <在正文消息中。在这种情况下,不会显示正文。

例如使用这段代码,一切正常:

from gi.repository import Gtk, Notify

def callback(notification, action_name):
notification.close()
Gtk.main_quit()

Notify.init('test')
notification = Notify.Notification.new('Title', 'body')
notification.set_timeout(Notify.EXPIRES_NEVER)
notification.add_action('quit', 'Quit', callback)
notification.show()

Gtk.main()

但是这个有一个问题:

from gi.repository import Gtk, Notify

def callback(notification, action_name):
notification.close()
Gtk.main_quit()

Notify.init('test')
notification = Notify.Notification.new('Title', '<body')
notification.set_timeout(Notify.EXPIRES_NEVER)
notification.add_action('quit', 'Quit', callback)
notification.show()

Gtk.main()

我明白了:Notification where the body is not displayed

<在标题中,或者当我使用 > 时没有问题。

我试图逃避 < ,但它什么也没做。那么,我怎样才能显示包含 < 的正文呢? ?

最佳答案

我注意到在 Gtk 中有时会有 html 代码,比如在使用 set_markup 时。我尝试使用等效的 hmtl < 并且它工作正常:

from gi.repository import Gtk, Notify

def callback(notification, action_name):
notification.close()
Gtk.main_quit()

Notify.init('test')
notification = Notify.Notification.new('Title', '&lt;body&gt;')
notification.set_timeout(Notify.EXPIRES_NEVER)
notification.add_action('quit', 'Quit', callback)
notification.show()

关于python - Gtk 通知不显示持有 '<' 的正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30828872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com