You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置PySimpleGUI的SystemTray.notify通知显示时长参数

PySimpleGUI SystemTray.notify 通知参数设置方案

报错原因

你调用时报错是因为SystemTray.notify的显示时长参数名并非duration,官方定义的合法参数如下:

  • display_duration_in_ms:通知总显示时长,单位为毫秒,默认值为10000(即10秒)
  • fade_in_duration:通知淡入效果时长,单位为毫秒,默认值为500
  • fade_out_duration:通知淡出效果时长,单位为毫秒,默认值为500
  • alpha:通知窗口透明度,取值范围为0~1,1为完全不透明,默认值为0.9

正确调用示例

自定义10秒显示时长

sg.SystemTray.notify('Notification Title', 'This is the notification message', display_duration_in_ms=10000)

通知直到用户点击才消失

Windows平台下可将显示时长设置为超大值(如1小时),用户点击通知或手动关闭时会提前消失:

sg.SystemTray.notify('Notification Title', 'This is the notification message', display_duration_in_ms=3600000)

注意事项

Windows 10自带全局通知显示时长限制,可在「系统设置 - 通知 - 通知显示时长」中调整全局上限,如果你设置的自定义时长超出系统全局最大值,会自动以系统设置的时长为准。


内容的提问来源于stack exchange,提问作者Biorez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 02:39:04