python实现通知
import win32api, win32con, win32gui
import time
class Taskbar:
def __init__(self):
self.visible = 0
message_map = {
win32con.WM_DESTROY: self.onDestroy,
}
# Register the Window class.
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32api.GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map
classAtom = win32gui.RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
exStyle = win32con.WS_EX_TOPMOST # win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_TOPMOST #| win32con.WS_EX_NOACTIVATE
self.hwnd = win32gui.CreateWindowEx(exStyle, classAtom, "Taskbar Demo", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
win32gui.UpdateWindow(self.hwnd)
icon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
self.setIcon(icon)
self.show()
def setIcon(self, hicon, tooltip=None):
self.hicon = hicon
self.tooltip = tooltip
def showBaloon(self, title='标题', content='内容'):
flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_INFO
nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon, "", content, 10, title,
win32gui.NIIF_INFO)
win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)
def show(self):
"""Display the taskbar icon"""
flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE
if self.tooltip is not None:
flags |= win32gui.NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon, self.tooltip)
else:
nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon)
if self.visible:
self.hide()
win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
self.visible = 1
def hide(self):
"""Hide the taskbar icon"""
if self.visible:
nid = (self.hwnd, 0)
win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
self.visible = 0
def onDestroy(self, hwnd, msg, wparam, lparam):
self.hide()
win32gui.PostQuitMessage(0) # Terminate the app.
if __name__ == '__main__':
t = Taskbar()
content = """
auto_cv 说明:
1. 按r绘制roi,绿色框线选者区域
2. 按t绘制tpl,红色框线截图
3. 按f绘制offset位置,红色点
按esc退住出绘制,按c清除绘制,按s重新截图
"""
t.showBaloon(title='截图提示', content=content)
time.sleep(3)
from win10toast import ToastNotifier
toaster = ToastNotifier()
toaster.show_toast('news1', 'i love 中森名菜!', icon_path='E:\idle.ico', duration=10)
toaster.show_toast('news2', 'i love 中森名菜!', icon_path='E:\idle.ico', duration=10)
本文作者: 永生
本文链接: https://yys.zone/detail/?id=240
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
评论列表 (0 条评论)