0% found this document useful (0 votes)
4 views3 pages

Takslist

This document describes a Task Manager application built using Tkinter in Python. It allows users to add, edit, and delete tasks, with tasks saved in a JSON file for persistence. The application features a user-friendly interface with buttons for task management and input fields for task details.

Uploaded by

Raihan Ansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Takslist

This document describes a Task Manager application built using Tkinter in Python. It allows users to add, edit, and delete tasks, with tasks saved in a JSON file for persistence. The application features a user-friendly interface with buttons for task management and input fields for task details.

Uploaded by

Raihan Ansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import tkinter as tk

from tkinter import messagebox


import json
import os

class TaskManager:
def __init__(self, root):
self.root = root
self.root.title("Task Manager")
self.root.geometry("500x500")
self.root.configure(bg="#F5F5F5")

self.tasks = []
self.load_tasks()

self.title_label = tk.Label(self.root, text="Task Manager",


font=("Helvetica", 20, "bold"), bg="#F5F5F5", fg="#4A4A4A")
self.title_label.pack(pady=20)

self.task_frame = tk.Frame(self.root, bg="#F5F5F5")


self.task_frame.pack(fill="both", expand=True, padx=20, pady=10)

self.add_task_button = tk.Button(self.root, text="Add Task",


command=self.add_task_window, bg="#A0D8D0", fg="#4A4A4A", font=("Helvetica", 14,
"bold"), width=10, borderwidth=0, activebackground="#B2E0DE")
self.add_task_button.pack(pady=10)

self.load_task_list()

def load_task_list(self):
for widget in self.task_frame.winfo_children():
widget.destroy()

for i, task in enumerate(self.tasks):


task_text = f"{i + 1}. {task['name']} - {task['description'][:20]}..."
task_label = tk.Label(self.task_frame, text=task_text, anchor="w",
font=("Helvetica", 12), bg="#E8F9F2", fg="#4A4A4A", padx=10, pady=5)
task_label.grid(row=i, column=0, sticky="we", padx=5, pady=2)

edit_button = tk.Button(self.task_frame, text="Edit", command=lambda


i=i: self.edit_task(i), bg="#FFD9B5", fg="#4A4A4A", font=("Helvetica", 10, "bold"),
width=5, borderwidth=0, activebackground="#FFE0B2")
edit_button.grid(row=i, column=1, padx=5)

delete_button = tk.Button(self.task_frame, text="Delete",


command=lambda i=i: self.delete_task(i), bg="#FFABAB", fg="#4A4A4A",
font=("Helvetica", 10, "bold"), width=5, borderwidth=0, activebackground="#FF9E9E")
delete_button.grid(row=i, column=2, padx=5)

self.task_frame.grid_columnconfigure(0, weight=1)

def add_task_window(self):
self.new_task_window = tk.Toplevel(self.root)
self.new_task_window.title("Add Task")
self.new_task_window.geometry("300x250")
self.new_task_window.configure(bg="#F5F5F5")

tk.Label(self.new_task_window, text="Task Name", bg="#F5F5F5",


fg="#4A4A4A", font=("Helvetica", 12)).pack(pady=10)
self.task_name_entry = tk.Entry(self.new_task_window, width=30,
font=("Helvetica", 12), bd=2, relief="flat", highlightbackground="#B0BEC5")
self.task_name_entry.pack(pady=5)

tk.Label(self.new_task_window, text="Description", bg="#F5F5F5",


fg="#4A4A4A", font=("Helvetica", 12)).pack(pady=10)
self.task_description_entry = tk.Entry(self.new_task_window, width=30,
font=("Helvetica", 12), bd=2, relief="flat", highlightbackground="#B0BEC5")
self.task_description_entry.pack(pady=5)

tk.Button(self.new_task_window, text="Add", command=self.add_task,


bg="#A0D8D0", fg="#4A4A4A", font=("Helvetica", 12, "bold"), width=10,
borderwidth=0, activebackground="#B2E0DE").pack(pady=20)

def add_task(self):
name = self.task_name_entry.get()
description = self.task_description_entry.get()

if name and description:


self.tasks.append({"name": name, "description": description})
self.save_tasks()
self.load_task_list()
self.new_task_window.destroy()
else:
messagebox.showwarning("Input Error", "Please enter both task name and
description.")

def edit_task(self, index):


self.edit_task_window = tk.Toplevel(self.root)
self.edit_task_window.title("Edit Task")
self.edit_task_window.geometry("300x250")
self.edit_task_window.configure(bg="#F5F5F5")

task = self.tasks[index]

tk.Label(self.edit_task_window, text="Task Name", bg="#F5F5F5",


fg="#4A4A4A", font=("Helvetica", 12)).pack(pady=10)
self.edit_task_name_entry = tk.Entry(self.edit_task_window, width=30,
font=("Helvetica", 12), bd=2, relief="flat", highlightbackground="#B0BEC5")
self.edit_task_name_entry.insert(0, task["name"])
self.edit_task_name_entry.pack(pady=5)

tk.Label(self.edit_task_window, text="Description", bg="#F5F5F5",


fg="#4A4A4A", font=("Helvetica", 12)).pack(pady=10)
self.edit_task_description_entry = tk.Entry(self.edit_task_window,
width=30, font=("Helvetica", 12), bd=2, relief="flat",
highlightbackground="#B0BEC5")
self.edit_task_description_entry.insert(0, task["description"])
self.edit_task_description_entry.pack(pady=5)

tk.Button(self.edit_task_window, text="Save", command=lambda:


self.save_edited_task(index), bg="#A0D8D0", fg="#4A4A4A", font=("Helvetica", 12,
"bold"), width=10, borderwidth=0, activebackground="#B2E0DE").pack(pady=20)

def save_edited_task(self, index):


new_name = self.edit_task_name_entry.get()
new_description = self.edit_task_description_entry.get()

if new_name and new_description:


self.tasks[index] = {"name": new_name, "description": new_description}
self.save_tasks()
self.load_task_list()
self.edit_task_window.destroy()
else:
messagebox.showwarning("Input Error", "Please enter both task name and
description.")

def delete_task(self, index):


confirm = messagebox.askyesno("Confirm Delete", "Are you sure you want to
delete this task?")
if confirm:
del self.tasks[index]
self.save_tasks()
self.load_task_list()

def save_tasks(self):
with open("tasks.json", "w") as file:
json.dump(self.tasks, file)

def load_tasks(self):
if os.path.exists("tasks.json"):
with open("tasks.json", "r") as file:
self.tasks = json.load(file)

if __name__ == "__main__":
root = tk.Tk()
app = TaskManager(root)
root.mainloop()

You might also like