Skip to main content

Windows 11 通知栏通知系统

简介

本项目旨在实现一个基于Windows 11的通知栏通知系统。通过使用winsdk库,我们可以创建丰富的通知消息,并支持多种交互方式,如按钮点击、输入框、进度条等。

目录

  1. 简介
  2. 安装依赖
  3. 核心功能
  4. 异步通知
  5. 更新进度
  6. 清除通知
  7. 总结
  8. 附录

安装依赖

在开始之前,确保已经安装了所需的依赖库。可以通过以下命令安装:

pip install winsdk
pip install pywin32

核心功能

创建通知

使用notify函数创建一个基本的通知:

notify(title="Hello", body="This is a notification", inputs=["Enter your name"])

添加图标

设置通知的图标:

notify(title="Hello", body="This is a notification", icon="path/to/icon.png")

添加图片

在通知中添加图片:

notify(title="Hello", body="This is a notification", image="path/to/image.png")

添加进度条

显示进度条:

notify(title="Hello", body="This is a notification", progress={"value": "50"})

添加音频

播放音频文件:

notify(title="Hello", body="This is a notification", audio="path/to/audio.mp3")

添加按钮

添加按钮以实现用户交互:

notify(title="Hello", body="This is a notification", button="Click me")

添加输入框

添加输入框以获取用户输入:

notify(title="Hello", body="This is a notification", input="Enter your name")

添加选择框

添加选择框以供用户选择:

notify(title="Hello", body="This is a notification", selection=["Option 1", "Option 2"])

异步通知

使用toast函数创建异步通知,支持更复杂的交互逻辑:

from packaging_tutorial.win11_notificationbar.win11_notificationbar import notify

notify(
    title="标题",
    body="内容",
    icon="https://example.com/icon.png",
    image="https://example.com/image.png",
    button="点击我",
    input="输入框",
    progress={"value": "0.5", "status": "进行中"},
    # audio="ms-winsoundevent:Notification.Looping.Alarm",
    on_click=lambda: print("点击了通知"),

)

img.png

更新进度

动态更新通知中的进度条:

update_progress({"value": "75"})

总结

通过本项目,我们实现了在Windows 11中创建丰富且交互性强的通知系统。这些功能可以帮助开发者更好地与用户进行互动,提升用户体验。

Metadata

Release files for win11-notificationbar 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for win11-notificationbar 0.0.2
File Size Uploaded
win11_notificationbar-0.0.2.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for win11-notificationbar 0.0.2
File Interpreter ABI Platform
win11_notificationbar-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / win11_notificationbar-0.0.2.tar.gz

Download URL win11_notificationbar-0.0.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aa46fa78b6abb49c2853273957b95f1e3061d5e5bbe4b510493b54a0462da828
BLAKE2b-256 checksum
How to use checksums
2ff3423c7954a1bd28f1516e7363257a13760ae4318aaa44909a6a6c725fa53e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Release files / win11_notificationbar-0.0.2-py3-none-any.whl

Download URL win11_notificationbar-0.0.2-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
faab65f511404b484aadc0d419f1b57ca5e1f3e26a8411a37c3b39aa61cc67fa
BLAKE2b-256 checksum
How to use checksums
f206d2e43f519153fce797af09fc90cf6d2eeb15997396fe2c70807cf75e92d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page