Untitled
unknown
plain_text
7 months ago
1.8 kB
1
Indexable
Never
import tkinter as tk from tkinter import messagebox class TaskApp: def __init__(self, master): self.master = master master.title("Task Manager") self.tasks = [] self.label = tk.Label(master, text="Task Manager") self.label.pack() self.task_entry = tk.Entry(master) self.task_entry.pack() self.add_button = tk.Button(master, text="Add Task", command=self.add_task) self.add_button.pack() self.task_listbox = tk.Listbox(master) self.task_listbox.pack() self.delete_button = tk.Button(master, text="Delete Task", command=self.delete_task) self.delete_button.pack() self.complete_button = tk.Button(master, text="Mark as Complete", command=self.complete_task) self.complete_button.pack() def add_task(self): task = self.task_entry.get() if task: self.tasks.append(task) self.task_listbox.insert(tk.END, task) self.task_entry.delete(0, tk.END) def delete_task(self): selection = self.task_listbox.curselection() if selection: index = selection[0] del self.tasks[index] self.task_listbox.delete(index) def complete_task(self): selection = self.task_listbox.curselection() if selection: index = selection[0] task = self.tasks[index] messagebox.showinfo("Task Completed", f"Task '{task}' marked as complete!") self.task_listbox.itemconfig(index, {'bg':'gray'}) self.task_listbox.selection_clear(index) def main(): root = tk.Tk() app = TaskApp(root) root.mainloop() if __name__ == "__main__": main()
Leave a Comment