使用python的交互式通知windows 10
我想知道是否可以用Windows10显示通知,当按下时,它会执行特定的操作。我知道关于使用python的交互式通知windows 10,python,tkinter,notifications,windows-10,Python,Tkinter,Notifications,Windows 10,我想知道是否可以用Windows10显示通知,当按下时,它会执行特定的操作。我知道关于plyer和win10toast的内容,但在这两个模块中,我看不到将其配置为与单击一起工作的方法。我想要它,这样当我按下它时,就会打开一个链接或运行一些功能,以使用tkinter。关于这一点的问题现在要么没有答案,要么不相容。你们知道吗 片段1: from win10toast import ToastNotifier noti = ToastNotifier() noti.show_toast('Rando
plyer
和win10toast
的内容,但在这两个模块中,我看不到将其配置为与单击一起工作的方法。我想要它,这样当我按下它时,就会打开一个链接或运行一些功能,以使用tkinter
。关于这一点的问题现在要么没有答案,要么不相容。你们知道吗
片段1:
from win10toast import ToastNotifier
noti = ToastNotifier()
noti.show_toast('Random','Hello World',icon_path='ico.ico',duration=60)
from plyer.utils import platform
from plyer import notification
notification.notify(
title='Here is the title',
message='Here is the message',
app_name='Here is the application name',
app_icon='path/to/the/icon.' + ('ico' if platform == 'win' else 'png')
)
此外,尽管给出了duration=60
,但它在大约5秒后会自动关闭
片段2:
from win10toast import ToastNotifier
noti = ToastNotifier()
noti.show_toast('Random','Hello World',icon_path='ico.ico',duration=60)
from plyer.utils import platform
from plyer import notification
notification.notify(
title='Here is the title',
message='Here is the message',
app_name='Here is the application name',
app_icon='path/to/the/icon.' + ('ico' if platform == 'win' else 'png')
)
经过一些研究,我发现win10toast
可以与win32gui
一起工作,对其进行一些配置可以使其工作。但我不确定是什么
提前感谢您可以使用
callback\u on\u click
方法在单击通知时执行回调
如本线程中所述,您需要安装
pip安装-e git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast由于单击时的回调\u
尚未与wintoast
合并
您将收到一个错误,但新版本的toastNotifier
将与现有版本一起复制
您必须从src.win10toast.win10toast导入到stnotifier,而不是
从win10toast导入到stNotifier
以便在单击方法时访问回调
请检查代码片段
from src.win10toast.win10toast import ToastNotifier
import tkinter as tk
from tkinter import *
import webbrowser
top = tk.Tk()
top.geometry('50x50')
top.title('shop')
url = 'http://www.google.com'
def notify():
noti.show_toast('Random','Hello World',duration=60, threaded=True,callback_on_click=action)
def action():
webbrowser.open_new(url)
print("Done")
noti = ToastNotifier()
btn = Button(top, text= "Enter", command=notify)
btn.pack()
top.mainloop()
注意-确保在show_toast()
中使用threaded=True
,以便允许在toast仍处于活动状态时执行程序的其余部分。否则你的gui就会冻结。我只是想出来了,我只是把文件从github复制粘贴到了官方图书馆。你能帮我回答一下吗comment@CoolCloud很高兴你找到了另一个解决办法。请确保它不会中断其他功能。感谢您的回复,因为我正在测试一个需要堆栈通知的程序,您可以立即删除它。您给出的答案是什么?是的,很好