Creating your alarm in Python can be anything between fun, educating, useful and even liberating.

For example, Windows alarm application is pretty but sometimes it’s too tedious adjust each parameter with the mouse and you may wish to type the values.

With Python you can create an alarm that works exactly the way you do and it can be a great learning project as well.

So, we have prepared numerous different methods that can count as an alarm and some of them are very cool.

These ideas will construct the core program of the alarm application. You can combine any of them with the Task Scheduling with Python method and you will have your own home-cooked alarm.

Creating Creative Alarms (w/ Python)

1- Web Browser Method

Let’s start with the web browser method. You can easily open any page on your default web browser using webbrowser library.

import webbrowser"")

So, just find a video you’d like to set as an alarm. It can be your favorite music or something inspirational on Youtube or another video site.

Check out “New Day” in this link from 50 Cent, Alicia Keys and Dr. Dre.

Alternatively you can set the link to 

  • your favorite movie clips, 
  • upcoming movie trailers, 
  • your favorite Youtube Vlogger, 
  • nature sounds (ocean, forest, wind, rain etc.)
  • bird sounds
  • cute animals
  • puppy videos 
  • funny videos etc.
So, the video depends on your preference, the event and the environment. You might choose different setups for an event like waking up, reminder of an event or reminder for taking a break.

2- Print Method

This one is my absolute favorite. Its beauty is its simplicity.
Apparently if try to print “\a”, this triggers a Windows notification sound (I think it’s called warning sound.)
So all you have to do is print it.
For a more sophisticated code you’d wanna put it in a loop or it will be too short to act as an alarm. But once in a loop it actually works surprisingly well. Very elegant and creative in my opinion.
Also, time library will be used to create a little bit of delay between each chime.
import time

for i in range(5):

This will create 5 Windows sounds with approximately 1 sec breaks.

You can also create a nested loop to produce blocks of these with a longer break in between. Check out this code:

It will produce 10 blocks of alarm tunes which will consist of 4 chimes. Between blocks there will be a 3 second break. I don’t know if it’s just me but it’s mind blowing to me to be able to create something like this from print function and a couple of loops. Well, there is also the time library but I think you know what I mean.

import time

for i in range(10):
    for i in range(4):

3- Proper Beep method from the win32api

Now, this is also simply a beep but it’s a more proper and complete method than the print method. Using win32api library you can actually make a precision on the frequency of the sound and adjust its length to the milisecond.

This opens the door for lots of sound creativity. Check out this alarm tune creation method which will produce unique sequence of sound every time it’s run because of the implementation of random library’s randint method:

Note: Frequency range is limited to approximately something like 37 to 32000.

Lower frequencies will create a very deep sound while high frequencies produce high pitch sounds.

Also, random library’s ranint simply produces a random integer between the values its given.

import win32api
import random

for i in range(5):
    win32api.Beep(random.randint(37,10000), random.randint(750,3000))

Another approach to Beep method from win32api as an alarm:

Increasing frequency and decreasing length.

for i in range(13):

4- Play a local sound

This might be the most appropriate approach if you’re particular about the exact sound you’re wishing to get from the alarm. It can also be helpful in cases where you are missing an internet connection.

Playing local sound is easy:

All you have to do is import os library and make use of its .system method.

import os

If you use a path just make sure to use double backslashes instead of regular slashes. This is necessary for Windows to recognize the path.

You can also use os.system method to open any other file such as video clips or movies.

5- Same thing with win32com.client

You can also use the Run method from win32com.client to run any file in your system locally. You can also use this method as an alternative to webbrowser because if you pass a web link as an argument to Windows Run it will automatically Run it in your default browser.

import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")

Bonus: – Python Alarm Library on Pypi

If you’re still not satisfied with any of these methods or if you don’t want to deal with the Task Scheduling part (which is a fantastic method to improve your coding skill-set and practice Python) you can also check out this interesting alarm library created for Python here

And you can check out some other cool scripting ideas from HolyPython here.

Thanks for reading.

Please share if this article was helpful to you.

Recommended Posts