Categories We Write About

Build a Python reminder app

Creating a simple Python reminder app can be a great way to learn about time manipulation and basic user interfaces. Below is a Python script that uses tkinter for the graphical user interface (GUI), and time for scheduling the reminders. It also utilizes plyer for sending system notifications.

Step 1: Install Necessary Libraries

If you don’t already have plyer installed, you can install it using pip:

bash
pip install plyer

Step 2: Create the Reminder App

Here is the Python code for the reminder app:

python
import tkinter as tk from tkinter import messagebox import time from plyer import notification from datetime import datetime class ReminderApp: def __init__(self, root): self.root = root self.root.title("Reminder App") # Labels and Entry Fields self.label1 = tk.Label(root, text="Enter Reminder:") self.label1.pack(pady=10) self.reminder_text = tk.Entry(root, width=50) self.reminder_text.pack(pady=10) self.label2 = tk.Label(root, text="Enter Time (HH:MM format):") self.label2.pack(pady=10) self.time_text = tk.Entry(root, width=20) self.time_text.pack(pady=10) # Button to set reminder self.set_button = tk.Button(root, text="Set Reminder", command=self.set_reminder) self.set_button.pack(pady=20) def set_reminder(self): reminder = self.reminder_text.get() reminder_time = self.time_text.get() if not reminder or not reminder_time: messagebox.showerror("Input Error", "Please fill in both fields.") return try: reminder_hour, reminder_minute = map(int, reminder_time.split(":")) except ValueError: messagebox.showerror("Input Error", "Please enter time in HH:MM format.") return current_time = datetime.now() reminder_time_obj = current_time.replace(hour=reminder_hour, minute=reminder_minute, second=0, microsecond=0) # If the reminder time has already passed today, set it for the next day if reminder_time_obj < current_time: reminder_time_obj = reminder_time_obj.replace(day=current_time.day + 1) time_diff = (reminder_time_obj - current_time).total_seconds() # Inform the user messagebox.showinfo("Reminder Set", f"Reminder set for {reminder_time_obj.strftime('%Y-%m-%d %H:%M:%S')}.") # Schedule the reminder self.root.after(int(time_diff * 1000), self.show_reminder, reminder) def show_reminder(self, reminder): notification.notify( title="Reminder", message=reminder, timeout=10 # Notification duration in seconds ) messagebox.showinfo("Reminder", f"Reminder: {reminder}") if __name__ == "__main__": root = tk.Tk() app = ReminderApp(root) root.mainloop()

Step 3: How the App Works

  1. GUI:

    • It provides a user-friendly window using tkinter where the user can input a reminder message and a time (in HH:MM format).

  2. Input Fields:

    • The user can input the reminder text and time. The app will check if both are entered correctly.

  3. Reminder Time Handling:

    • The app calculates how much time is left until the reminder time. If the reminder time has already passed for today, it will set the reminder for the same time on the next day.

  4. Notification:

    • When the time arrives, a desktop notification is triggered using plyer. Additionally, the app will display a pop-up message box.

How to Run the App

  1. Copy and paste the code into a Python file (e.g., reminder_app.py).

  2. Run the script in your terminal:

bash
python reminder_app.py

Improvements and Additional Features

  • Multiple reminders: Currently, the app only supports one reminder at a time. You could extend it to handle multiple reminders.

  • Recurring reminders: Set up reminders that recur daily, weekly, or at custom intervals.

  • Sound notifications: You could add a sound alert along with the notification.

  • Save reminders: Allow users to save their reminders in a text file or database for persistence.

Let me know if you’d like help implementing any of these features!

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About