In this blog article, you will learn how to create a Drink Water Desktop Notifier application for your PC in a few simple steps using Python.
Till the end of this blog you'll be able to:
- Create a Desktop Notifier.
But wait! Why Notifications are important and what's their purpose?
-Notifications help people to remember things. It is a small piece of text which appears on the desktop or mobile screen to inform the user about the updates or any other important pieces of information.
I think after reading this you've got an idea of how this application would be useful on daily basis.
So let's get started...
Python has an incredible vast library of useful modules, so let's use some of them in our program to build our application.
Some of them which will be used by us are:
1. time
2. plyer
Why to use time and plyer?
- time Module
Python time module provides many ways of representing time in code, such as objects, numbers, and strings. It also provides functionality other than representing time, like waiting during code execution and measuring the efficiency of your code. It is built in module in python
- plyer (for creating notifications on your PC)
Plyer is python library used to access the features of the hardware. This does not comes built-in in Python.
So as plyer is not built-in in python so we need to install it externally, for that open your command prompt and type the following command
pip install plyer
If you wish to know more about it, you can refer to Plyer Documentation.
After that you are good to go for coding part. Here is the code...
Let's take a look what parameters means:
- title: Title for notification.
- message: Message for notification.
- app_icon: Icon to be displayed along with the message.
- timeout: Tells how much time a notification should show up on the desktop.
So let's pass the parameter to notify method of notification class. I have passed specified parameters in code to notify method.
Considering time module here time.sleep(): Tells after what interval of time the notification should popup.
Making your application run in the background.
So you finally created a python application and it runs fine when you go and run it. But don't you think this is a tedious job, every time running your application to get a notification? Here is a solution, you can make this automated by running your application as a background process in your PC.
How to make a python application to run in the background?
Just follow this simple command to make your application run in the background, note you need to type this command in command prompt. (first navigate to the folder using command prompt where your python .py file is located in which you have written the code and then type this command and hit enter.
Note: replace "file_name" with your file name containing python code.
pythonw.exe .\<file_name>
example:
pythonw.exe .\desktopNotifier.py
Once you have enter this command it will once give you notification and then it will sleep till specified interval using time.sleep() method.
So that's it your application now starts running in the background. But how can we be so sure it is running in background let's see that too... Open task manager in your pc and you can see that in background process python is running.
If you want to stop it from running in background you can simply End Task as I have shown here.
You can use this approach in many areas, itβs completely up to you how to use this application. It's that simple. You can play around with the library, explore more features and even customize it further.
Hope this article had created interest in you to create your own customized desktop notification application.β₯π»π
You can find all the code at my GitHub Repository . Drop a star if you find it useful. Thank you for reading, I would love to connect with you at Twitter.
If any doubts feel free to ask in the comment section. Do share your feedback and suggestions!