Categories We Write About

Create a GUI for managing tasks

Here’s a simple Python-based GUI for managing tasks using Tkinter, a standard GUI library included with Python. This app allows users to add, view, mark complete, and delete tasks.

python
import tkinter as tk from tkinter import messagebox class TaskManager: def __init__(self, root): self.root = root self.root.title("Task Manager") self.root.geometry("400x500") self.tasks = [] self.task_input = tk.Entry(self.root, font=("Arial", 14), width=25) self.task_input.pack(pady=20) self.add_button = tk.Button(self.root, text="Add Task", command=self.add_task, width=20, bg="#28a745", fg="white") self.add_button.pack() self.task_listbox = tk.Listbox(self.root, selectmode=tk.SINGLE, font=("Arial", 12), width=35, height=15) self.task_listbox.pack(pady=20) self.complete_button = tk.Button(self.root, text="Mark Complete", command=self.mark_complete, width=20, bg="#007bff", fg="white") self.complete_button.pack(pady=5) self.delete_button = tk.Button(self.root, text="Delete Task", command=self.delete_task, width=20, bg="#dc3545", fg="white") self.delete_button.pack(pady=5) def add_task(self): task = self.task_input.get() if task: self.tasks.append({"task": task, "completed": False}) self.update_tasks() self.task_input.delete(0, tk.END) else: messagebox.showwarning("Input Error", "Please enter a task.") def update_tasks(self): self.task_listbox.delete(0, tk.END) for i, task in enumerate(self.tasks): display_text = f"[✓] {task['task']}" if task["completed"] else f"[ ] {task['task']}" self.task_listbox.insert(tk.END, display_text) def mark_complete(self): selected = self.task_listbox.curselection() if selected: index = selected[0] self.tasks[index]["completed"] = not self.tasks[index]["completed"] self.update_tasks() else: messagebox.showinfo("Selection Error", "Please select a task to mark complete.") def delete_task(self): selected = self.task_listbox.curselection() if selected: del self.tasks[selected[0]] self.update_tasks() else: messagebox.showinfo("Selection Error", "Please select a task to delete.") if __name__ == "__main__": root = tk.Tk() app = TaskManager(root) root.mainloop()

Features:

  • Add Task: Input a task name and click to add it.

  • Mark Complete: Toggles a checkmark for task status.

  • Delete Task: Removes a selected task from the list.

This script runs as a desktop app. You can expand it with features like saving tasks to a file or using a database. Let me know if you want a web-based version or one using a different GUI framework like PyQt or Kivy.

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