我正在使用win10toast为windows制作一个通知弹出窗口。有没有办法让通知静默?换句话说,我可以禁用我正在创建的通知的声音吗?我可以换个声音吗?
编辑:添加示例代码
我的示例代码:
from win10toast import ToastNotifier
toaster = ToastNotifier()
for i in range(0,70000000):
pass
toaster.show_toast("Hey User",
"The program is running pretty well. You should try to disable audio on me next though!",
icon_path=None,
duration=5)发布于 2019-07-21 03:43:33
您必须修改该库的源代码才能做到这一点。转到安装该库的文件夹,然后打开"__init__.py“文件。在顶部,在放置所有"win32gui“导入之后,编写from win32gui import NIIF_NOSOUND。
之后,转到第107行,您应该会看到这段代码:
Shell_NotifyIcon(NIM_MODIFY, (self.hwnd, 0, NIF_INFO,
WM_USER + 20,
hicon, "Balloon Tooltip", msg, 200,
title))在"title“参数后,放入"NIIF_NOSOUND",应该如下所示:
Shell_NotifyIcon(NIM_MODIFY, (self.hwnd, 0, NIF_INFO,
WM_USER + 20,
hicon, "Balloon Tooltip", msg, 200,
title, NIIF_NOSOUND))如果你想这样做,或者你必须进一步修改源代码,你可以添加一个新的参数到show_toast方法。如下所示:
# line 121
def show_toast(self, title="Notification", msg="Here comes the message",
icon_path=None, duration=5, threaded=False, sound=False):并进一步发送“声音”参数:
# line 130
if not threaded:
self._show_toast(title, msg, icon_path, duration, sound)
else:
if self.notification_active():
# We have an active notification, let is finish so we don't spam them
return False
self._thread = threading.Thread(target=self._show_toast, args=(title, msg, icon_path, duration, sound))
self._thread.start()
return True然后将参数添加到“隐藏的”_show_toast方法中:
# line 63
def _show_toast(self, title, msg,
icon_path, duration, sound):并执行if else语句来检查是否应该添加"NIIF_NOSOUND“标志:
# line 107
Shell_NotifyIcon(NIM_ADD, nid)
data = (self.hwnd, 0, NIF_INFO,
WM_USER + 20,
hicon, "Balloon Tooltip", msg, 200,
title)
if not sound:
data = data + (NIIF_NOSOUND,)
Shell_NotifyIcon(NIM_MODIFY, data)此参数需要修改通知行为和外观的InfoFlags的组合。阅读有关NIIF_NOSOUND标志和其他标志的更多信息。在这里您可以看到在"pywin32“pywin32 documentation中有哪些"NIIF”标志。
您可以在pywin32 Shell_NotifyIcon中查看有关Shell_NotifyIcon函数参数的更多信息。
Shell_NotifyIcon函数的第二个参数是一个表示"PyNOTIFYICONDATA“对象的元组,该对象接受不同的参数,您可以在pywin32 PyNOTIFYICONDATA 中查看有关此对象的更多信息。
注意:这对我在Windows10上是有效的。
https://stackoverflow.com/questions/56695061
复制相似问题