23
Create a simple pomodoro timer in python
If you're looking for a pretty useful yet simple python project, you've come to the right place!
A pomodoro timer is a special type of timer used to increase productivity.
It works something like this:
It works something like this:
To get started with making a pomodoro timer in python, you'll first need to install the "plyer" library by running
pip install plyer
or pip3 install plyer
.Then import these 2 libraries at the beginning of your python file:
import time
from plyer import notification
Next, define the variable which will represent the amount of pomodoros completed by the user, as well as an indicator that the pomodoro timer has started:
import time
from plyer import notification
count = 0
print("The pomodoro timer has started, start working!")
First, you'll need to put the timer in a
while True:
loop nested inside an if __name__ == "__main__":
statement ( if you're not familiar with it, here's a good explanation: https://stackoverflow.com/questions/419163/what-does-if-name-main-do ):if __name__ == "__main__":
while True:
Next, make the first notification function which will notify the user when they've finished a pomodoro:
if __name__ == "__main__":
while True:
notification.notify(
title = "Good work!",
message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
)
)
As you can see, this "notify()" function notifies the user that he/she has finished a pomodoro, and it indicates how many pomodoros the user has finished so far with the "count" variable.
Next, you'll need to create the "notify()" function which will notify the user once his/her 10 minutes of break time are over:
if __name__ == "__main__":
while True:
notification.notify(
title = "Good work!",
message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
)
notification.notify(
title = "Back to work!",
message = "Try doing another pomodoro...",
)
)
The only things left to do are:
if __name__ == "__main__":
while True:
time.sleep(1800)
count += 1
notification.notify(
title = "Good work!",
message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
)
time.sleep(600)
notification.notify(
title = "Back to work!",
message = "Try doing another pomodoro...",
)
If you put everything together, your pomodoro timer should look something like this:
import time
from plyer import notification
count = 0
print("The pomodoro timer has started, start working!")
if __name__ == "__main__":
while True:
time.sleep(1800)
count += 1
notification.notify(
title = "Good work!",
message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
)
time.sleep(600)
notification.notify(
title = "Back to work!",
message = "Try doing another pomodoro...",
)
Byeeeee👋
23