Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การแจ้งเตือน Windows 10 Toast ด้วย Python


เราสามารถสร้างตัวแจ้งเตือนสำหรับเหตุการณ์ที่เกิดขึ้นใน Windows โดยใช้ Python . มันง่ายมากด้วย win10toast โมดูล. หากคุณคุ้นเคยกับ ขนมปังปิ้ง ใน Android จากนั้นทำความเข้าใจการแจ้งเตือนของ Toast ด้วย Python เป็นชิ้นเค้ก เราสามารถสร้างการแจ้งเตือนได้ทุกเมื่อที่มีเหตุการณ์เกิดขึ้นเป็นส่วนที่เหลือ มาดูกันค่ะ

เรียกใช้คำสั่งต่อไปนี้ใน บรรทัดคำสั่ง เพื่อติดตั้ง win10toast โมดูล

pip install win10toast

หากโมดูลติดตั้งสำเร็จ คุณจะได้รับผลลัพธ์ต่อไปนี้เมื่อคุณเรียกใช้คำสั่ง

Collecting win10toast
Downloading https://files.pythonhosted.org/packages/d4/ba/95c0ea87d9bcad68b90d8cb130a313b939c88d8338a2fed7c11eaee972fe/win10toast-0.9-py2.py3-none-any.whl
Collecting pypiwin32 (from win10toast)
Downloading https://files.pythonhosted.org/packages/d0/1b/2f292bbd742e369a100c91faa0483172cd91a1a422a6692055ac920946c5/pypiwin32-223-py3-none-any.whl
Requirement already satisfied: setuptools in c:\users\hafeezulkareem\anaconda3\lib\site-packages (from win10toast) (40.8.0)
Requirement already satisfied: pywin32>=223 in c:\users\hafeezulkareem\anaconda3\lib\site-packages (from pypiwin32->win10toast) (223)
Installing collected packages: pypiwin32, win10toast
Successfully installed pypiwin32-223 win10toast-0.9

ขั้นตอนในการสร้างการแจ้งเตือน Toast

  • นำเข้าคลาส ToastNotifier จาก win10toast

  • ยกตัวอย่างชั้นเรียน

  • เรียกใช้เมธอด show_toast('title', 'message', duration =time_in_sec, icon_path ='path to .ico file') พร้อมอาร์กิวเมนต์ที่ต้องการ

  • คุณจะได้รับ True เป็นเอาต์พุตหลังจากระยะเวลาการแจ้งเตือนเสร็จสิ้น หากสำเร็จ

มาดูตัวอย่างกันง่ายๆ

ตัวอย่าง

## program to generate a simple toast notifier
from win10toast import ToastNotifier
## instantiating the class
notifier = ToastNotifier()
## invoking the show_toast() method with required arguments notifier.show_toast("Sample Notification", "You are learning at Tutorialspoint", duration = 25, icon_path = "globe.ico")

หากคุณเรียกใช้โปรแกรมข้างต้น คุณจะได้ผลลัพธ์ดังต่อไปนี้

การแจ้งเตือน Windows 10 Toast ด้วย Python

คุณสามารถเพิ่มโปรแกรมแจ้งเตือนนี้เมื่อมีเหตุการณ์เกิดขึ้นในระบบของคุณ หากคุณมีข้อสงสัยเกี่ยวกับบทแนะนำ โปรดระบุในส่วนความคิดเห็น