Fab*_*ook 10 python windows notifications
是否可以使用python在Windows中添加通知?就像一个包含有关更新或某些信息的通知框
在Windows中,如果你还没有通过这张图片说明..
小智 22
首先,使用pip
以下命令安装 win10toast :
pip install win10toast
Run Code Online (Sandbox Code Playgroud)
然后,导入它:
pip install win10toast
Run Code Online (Sandbox Code Playgroud)
创建一个名为 的变量toast
:
from win10toast import ToastNotifier
Run Code Online (Sandbox Code Playgroud)
显示toast
变量:
toast = ToastNotifier()
Run Code Online (Sandbox Code Playgroud)
它应该是这样的:
小智 12
您可以使用 plyer 来显示通知:
from plyer import notification
notification.notify(
title = "Sample Notification",
message = "This is a sample notification",
timeout = 10
)
Run Code Online (Sandbox Code Playgroud)
或者您可以运行此代码并生成通知:
from plyer import notification
import tkinter as tk
root = tk.Tk()
tk.Label(root , text = 'NOTIFICATION DEVELOPER').grid(row = 0, column = 0)
tk.Label(root , text = 'Notification Title:').grid(row = 3, column = 0)
tk.Label(root , text = 'Notification Message').grid(row = 4, column = 0)
tk.Label(root , text = 'Seconds for which it appears'). grid(row = 5, column = 0)
t1 = tk.Entry(root)
t1.grid(row = 3, column = 1)
m = tk.Entry(root)
m.grid(row = 4, column = 1)
tm = tk.Entry(root)
tm.grid(row = 5, column = 1)
def strt():
a = int(tm.get())
notification.notify(
title = t1.get(),
message = m.get(),
timeout = a
)
tk.Button(root , text = 'START NOTIFICATION' , command = strt).grid(row = 6, column = 0)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
如果您希望在一段时间后再次显示通知,您可以使用 time.sleep(a) 并循环代码。(a = 再次显示通知的时间。
要插入图标,请使用 app_icon:
app_icon = 'Full path of .ico file'
Run Code Online (Sandbox Code Playgroud)