Desktop Notification In Python
Hello friends, In this segment, we are going to discuss how to create a desktop notification using Python. So before start writing program for creating a desktop notifier. Let me tell you how it is work and for writing the code that needs you to have.
For creating the desktop notifier in Python first you will have to install the win10toast module. For installing this module go to your Windows PowerShell or Command Prompt and type pip install win10toast and hit enter. When the win10toast will install, you will be ready to write code for creating a desktop notifier.
Python Desktop Notifier
Now got to your IDE and start writing code for creat desktop notifier. I will explain everything after writing the code because then you can understand everything very well. So the code is given below.
import time from win10toast import ToastNotifier remTime = input("Input Time in 24hr format(HH:MM:SS) to set reminder->") remMssg = input("Enter your message:>") while True: current_time = time.strftime("%H:%M:%S") if current_time == remTime: print(current_time) break; notify = ToastNotifier() notify.show_toast("Notification",remMssg)
As you can see the code above first I have import time and then after import ToastNotifier from win10toast. Win10toast is a Python library that gives access to us to create a desktop notification. The variable remTime stores that time, when you have to display your notification. The variable remMssg stores the notification message which you want to display in the notification. Now start the loop where time.strftime() function provides the time to the variable current_time. Whenever the current_time equals to remTime it displays current_time. The notify.show_toast(“Notification”,remMssg) function displays the notification message in the Notification.
Also read: Differences between list and tuple in Python
Let’s talk about output when you will run the above code it will look like this.
Output: Input Time in 24hr format(HH:MM:SS) to set reminder->10:37:00 Enter your message:>it's time to study
Here time and message are inputted by the user. Whenever the inputted time will be equals to current time this will show a notification with the user inputted message. And then the output will be-:
output:
Input Time in 24hr format(HH:MM:SS) to set reminder->10:37:00 Enter your message:>it's time to study 10:37:00 Process finished with exit code 0
Leave a Reply