The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a Python GUI to manage tasks

Creating a Python GUI to manage tasks can be efficiently done using tkinter, the built-in GUI library in Python. Below is a complete example of a simple Task Manager app with functionalities to add, delete, and mark tasks as completed.

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 = [] # Title label self.title_label = tk.Label(root, text="Task Manager", font=("Helvetica", 18)) self.title_label.pack(pady=10) # Frame for task entry and add button self.entry_frame = tk.Frame(root) self.entry_frame.pack(pady=10) self.task_entry = tk.Entry(self.entry_frame, width=30, font=("Helvetica", 14)) self.task_entry.pack(side=tk.LEFT, padx=(0,10)) self.add_btn = tk.Button(self.entry_frame, text="Add Task", command=self.add_task) self.add_btn.pack(side=tk.LEFT) # Listbox to show tasks self.task_listbox = tk.Listbox(root, font=("Helvetica", 14), width=40, height=15, selectmode=tk.SINGLE) self.task_listbox.pack(pady=10) # Scrollbar for the listbox self.scrollbar = tk.Scrollbar(root) self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.task_listbox.config(yscrollcommand=self.scrollbar.set) self.scrollbar.config(command=self.task_listbox.yview) # Buttons frame for delete and mark completed self.buttons_frame = tk.Frame(root) self.buttons_frame.pack(pady=10) self.delete_btn = tk.Button(self.buttons_frame, text="Delete Task", command=self.delete_task) self.delete_btn.pack(side=tk.LEFT, padx=5) self.complete_btn = tk.Button(self.buttons_frame, text="Mark Completed", command=self.mark_completed) self.complete_btn.pack(side=tk.LEFT, padx=5) def add_task(self): task_text = self.task_entry.get().strip() if task_text == "": messagebox.showwarning("Warning", "Please enter a task.") return self.tasks.append({"task": task_text, "completed": False}) self.update_task_list() self.task_entry.delete(0, tk.END) def delete_task(self): selected_idx = self.task_listbox.curselection() if not selected_idx: messagebox.showwarning("Warning", "Please select a task to delete.") return index = selected_idx[0] del self.tasks[index] self.update_task_list() def mark_completed(self): selected_idx = self.task_listbox.curselection() if not selected_idx: messagebox.showwarning("Warning", "Please select a task to mark completed.") return index = selected_idx[0] self.tasks[index]["completed"] = True self.update_task_list() def update_task_list(self): self.task_listbox.delete(0, tk.END) for task in self.tasks: display_text = task["task"] if task["completed"]: display_text += " ✅" self.task_listbox.insert(tk.END, display_text) if __name__ == "__main__": root = tk.Tk() app = TaskManager(root) root.mainloop()

Features:

  • Add new tasks.

  • Delete selected tasks.

  • Mark tasks as completed (adds a checkmark).

  • Scrollable list for tasks.

You can run this script directly if you have Python installed. Let me know if you’d like me to add features like saving tasks to a file or more!

Share this Page your favorite way: Click any app below to share.

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

We respect your email privacy

Categories We Write About