Categories We Write About

Reminder App with Python and GUI

Creating a reminder app using Python with a graphical user interface (GUI) can be efficiently done using the Tkinter library, which is built into Python and provides easy tools for building desktop apps. Below is a detailed guide and full example to build a simple yet functional reminder app with features like setting reminders, displaying them, and notifications.


Building a Reminder App with Python and GUI

Key Features:

  • Add a reminder with a message and time.

  • Show a list of upcoming reminders.

  • Notify the user when the reminder time is reached.

  • Basic GUI layout for user input and reminder display.

Required Libraries:

  • tkinter for GUI

  • datetime for handling reminder times

  • threading for background checking of reminders

  • playsound or system notification (optional for alert sounds)

You can install playsound using:

bash
pip install playsound

Step-by-step Implementation

1. Setting up the main window and input fields

We need fields for reminder message and reminder time (hour and minute).

2. Storing reminders

A list will hold reminders as dictionaries with message and time.

3. Background thread to check reminders

Continuously check if any reminder time matches the current time and notify the user.

4. Notification popup

A simple popup window or sound alert.


Complete Code Example:

python
import tkinter as tk from tkinter import messagebox from datetime import datetime, timedelta import threading import time import sys try: from playsound import playsound sound_available = True except ImportError: sound_available = False class ReminderApp: def __init__(self, root): self.root = root self.root.title("Reminder App") self.reminders = [] # GUI Components tk.Label(root, text="Reminder Message:").grid(row=0, column=0, padx=5, pady=5) self.msg_entry = tk.Entry(root, width=40) self.msg_entry.grid(row=0, column=1, padx=5, pady=5, columnspan=2) tk.Label(root, text="Hour (24h):").grid(row=1, column=0, padx=5, pady=5) self.hour_entry = tk.Entry(root, width=5) self.hour_entry.grid(row=1, column=1, sticky='w', padx=5, pady=5) tk.Label(root, text="Minute:").grid(row=1, column=2, padx=5, pady=5) self.minute_entry = tk.Entry(root, width=5) self.minute_entry.grid(row=1, column=3, sticky='w', padx=5, pady=5) self.add_btn = tk.Button(root, text="Add Reminder", command=self.add_reminder) self.add_btn.grid(row=2, column=1, columnspan=2, pady=10) tk.Label(root, text="Upcoming Reminders:").grid(row=3, column=0, padx=5, pady=5, sticky='w') self.reminder_listbox = tk.Listbox(root, width=50) self.reminder_listbox.grid(row=4, column=0, columnspan=4, padx=5, pady=5) # Start reminder checking thread self.running = True threading.Thread(target=self.check_reminders, daemon=True).start() def add_reminder(self): msg = self.msg_entry.get().strip() hour = self.hour_entry.get().strip() minute = self.minute_entry.get().strip() if not msg: messagebox.showwarning("Input Error", "Please enter a reminder message.") return if not hour.isdigit() or not minute.isdigit(): messagebox.showwarning("Input Error", "Please enter valid numeric values for hour and minute.") return hour = int(hour) minute = int(minute) if not (0 <= hour <= 23) or not (0 <= minute <= 59): messagebox.showwarning("Input Error", "Hour must be 0-23 and minute must be 0-59.") return now = datetime.now() reminder_time = now.replace(hour=hour, minute=minute, second=0, microsecond=0) if reminder_time < now: # If time is earlier than now, set for next day reminder_time += timedelta(days=1) reminder = {"message": msg, "time": reminder_time} self.reminders.append(reminder) self.update_reminder_list() # Clear entries self.msg_entry.delete(0, tk.END) self.hour_entry.delete(0, tk.END) self.minute_entry.delete(0, tk.END) messagebox.showinfo("Reminder Added", f"Reminder set for {reminder_time.strftime('%Y-%m-%d %H:%M')}") def update_reminder_list(self): self.reminder_listbox.delete(0, tk.END) for rem in sorted(self.reminders, key=lambda r: r["time"]): display = f"{rem['time'].strftime('%Y-%m-%d %H:%M')} - {rem['message']}" self.reminder_listbox.insert(tk.END, display) def check_reminders(self): while self.running: now = datetime.now() due_reminders = [r for r in self.reminders if r["time"] <= now] for rem in due_reminders: self.show_notification(rem["message"]) self.reminders.remove(rem) self.update_reminder_list() time.sleep(30) # Check every 30 seconds def show_notification(self, message): def popup(): messagebox.showinfo("Reminder", message) if sound_available: try: playsound('alert.mp3') # Put your alert sound file path here except: pass self.root.after(0, popup) def stop(self): self.running = False if __name__ == "__main__": root = tk.Tk() app = ReminderApp(root) root.protocol("WM_DELETE_WINDOW", lambda: (app.stop(), root.destroy())) root.mainloop()

Explanation:

  • GUI Input Fields: User enters reminder text, hour, and minute.

  • Reminder Storage: Reminders are stored in a list as dictionaries with the exact datetime.

  • Time Checking: A separate thread keeps checking every 30 seconds if any reminders are due.

  • Notification: When due, a popup appears with the reminder message. Optionally, it plays a sound if you provide a sound file named alert.mp3 in the script’s folder.

  • Time Logic: If the set time is earlier than current time, the app assumes the next day for that reminder.


Enhancements you can add:

  • Ability to delete or edit reminders.

  • Recurring reminders.

  • Better sound notification handling.

  • Persistent storage using files or databases.

  • Use of system notifications instead of Tkinter popups.

This code is a strong foundation for a desktop reminder app using Python and Tkinter.

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