Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python的交互式通知windows 10_Python_Tkinter_Notifications_Windows 10 - Fatal编程技术网

使用python的交互式通知windows 10

使用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

我想知道是否可以用Windows10显示通知,当按下时,它会执行特定的操作。我知道关于
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很高兴你找到了另一个解决办法。请确保它不会中断其他功能。感谢您的回复,因为我正在测试一个需要堆栈通知的程序,您可以立即删除它。您给出的答案是什么?是的,很好