alex_bn_lee

导航

[983] Add a notification after finishing the Python script

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:

  1. Using Plyer (Cross-Platform):

    • Install the plyer library using pip3 install plyer.
    • Import the notification module from plyer.
    • 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

posted on 2024-03-18 13:33  McDelfino  阅读(3)  评论(0编辑  收藏  举报