ref: How to implement a Python desktop notifier using the plyer module
You can generate a notification after your Python code finishes executing using various methods. Here are a few options:
-
Using Plyer (Cross-Platform):
- Install the
plyer
library usingpip3 install plyer
. - Import the
notification
module fromplyer
. - Add the following code snippet to your Python script:
import sys import time from plyer import notification def long_running_task(): print("Task started.") time.sleep(5) # Simulate a task that takes 5 seconds to complete print("Task completed.") # Run the long-running task long_running_task() # After the task is done, show a notification notification.notify( title='Python Script Execution', message='Your Python script has finished executing.', app_name='Python Notification' ) print("Notification has been sent.")
- This will display a notification when your code completes execution1
- Install the