How To make a windows Desktop Notifier For Python Beginners | Journal #4
So you know how YouTube for example can notify you right? Well how can we make this ourselves? I'm gonna teach you
Coding Time
Firstly we need to import the python packages. You might need to download plyer by typing ‘pip install plyer’ in the terminal.
import time
from plyer import notification
Lets actually start by making the variables. These will be a important part later on.
# Set the title and message for the notification
title = "Your title"
message = "Your description message"
duration = 10 # Set to whatever you want :) 10 duration = 10 seconds
Now how do we send the actual notification? Well we need to use the notification.notify() function. But now its your time to guess what we put in each section! Remember to add the commas else it won’t work.
notification.notify(
title=??,
message=??,
timeout=??
)
Well its really simple there is no need to worry. We just put everything which has the same name in the same item. So title=title. Simple Right?
notification.notify(
title=title,
message=message,
timeout=duration
)
Now this is fully optional but you can keep it there for longer and add this
# Optional: Add a delay to keep the notification on the screen for a few seconds
time.sleep(duration)
Finally, add it all together and you will get a final product. Now, if you want to show your skills off then do the Challenges below.
Spice Levels:
Mild 🌶
Not hard. Help in what we taught you today.
Hot 🌶🌶
Ooh! You are getting hot! This is getting hard now!
BLAZING HOT 🌶🌶🌶
Oh My Gosh To much spice to handle. Only some people can do this.
Challenge 1. Changing Variable Values 🌶
Make the Title Say ‘Hello’ and the Description to say ‘How Are You?’
Challenge 2. Changing Variables 🌶🌶
Change ~message = “Your description message”~ to ~description= “Your description message”~ How can you make it not give an error and still send the notification. Hint: Change a variable value in notification.notify()
Challenge 3. Changing Icons 🌶🌶🌶
Instead of your notification having a normal icon try making it whatever picture you want.
LINKS
Subscribe to Junior Developer Journal: Subscribe! Journal #4