首页 > 解决方案 > 是否可以在 Windows 10 通知(python win10toast 模块)中添加下划线/粗体文本?

问题描述

我正在开发一个在完成时生成通知的程序。它是可点击的,我想通过在通知中加下划线或加粗“点击这里”来夸大这一点。这可能吗?如果它不是 win10toast 中的一个功能,我可以使用另一个模块吗?

标签: pythonwindowswindows-10

解决方案


尝试:

from win10toast import ToastNotifier

def return_with_underline(x):
    lst1 = []
    for letter in x:
        if letter != ' ':
            lst1.append(letter)
            lst1.append('\u0332')
        else:
            lst1.append(letter)
    return '{:s}'.format(''.join(lst1))

toaster = ToastNotifier()

toaster.show_toast(return_with_underline('Click Here!'), "Hi", icon_path=None, duration=5)

这并不完美(不适用于空格),但您也可以使用其他 Unicode 字符,而不是\u03232

从这里得到这个(他们在谈论纯字符串,但它也在这里工作):

Python:字符串格式化程序以获得带下划线的标题


推荐阅读