create a todo list application
- User
create a todo list application
Assistant
Here's a simple Todo List application using Python and the Tkinter library for the GUI.
import tkinter as tk from tkinter import messagebox class TodoList: def __init__(self, root): self.root = root self.root.title("Todo List") self.tasks = [] # Task list self.task_list = tk.Listbox(self.root, width=40, height=10) self.task_list.pack(padx=10, pady=10) # New task entry self.new_task_label = tk.Label(self.root, text="New Task:") self.new_task_label.pack(padx=10, pady=5) self.new_task_entry = tk.Entry(self.root, width=40) self.new_task_entry.pack(padx=10, pady=5) # Buttons self.add_task_button = tk.Button(self.root, text="Add Task", command=self.add_task) self.add_task_button.pack(padx=10, pady=5) self.delete_task_button = tk.Button(self.root, text="Delete Task", command=self.delete_task) self.delete_task_button.pack(padx=10, pady=5) self.save_tasks_button = tk.Button(self.root, text="Save Tasks", command=self.save_tasks) self.save_tasks_button.pack(padx=10, pady=5) self.load_tasks_button = tk.Button(self.root, text="Load Tasks", command=self.load_tasks) self.load_tasks_button.pack(padx=10, pady=5) def add_task(self): task = self.new_task_entry.get() if task != "": self.tasks.append(task) self.task_list.insert(tk.END, task) self.new_task_entry.delete(0, tk.END) else: messagebox.showwarning("Warning!", "You must enter a task.") def delete_task(self): try: task_index = self.task_list.curselection()[0] self.task_list.delete(task_index) self.tasks.pop(task_index) except: messagebox.showwarning("Warning!", "You must select a task.") def save_tasks(self): with open("tasks.txt", "w") as f: for task in self.tasks: f.write(task + "\n") messagebox.showinfo("Info", "Tasks saved.") def load_tasks(self): try: with open("tasks.txt", "r") as f: self.tasks = f.readlines() self.tasks = [task.strip() for task in self.tasks] self.task_list.delete(0, tk.END) for task in self.tasks: self.task_list.insert(tk.END, task) except: messagebox.showwarning("Warning!", "No saved tasks found.") if __name__ == "__main__": root = tk.Tk() todo_list = TodoList(root) root.mainloop()Features:
- Add Task: Enter a new task in the text field and click the "Add Task" button to add it to the list.
- Delete Task: Select a task from the list and click the "Delete Task" button to remove it.
- Save Tasks: Click the "Save Tasks" button to save the current tasks to a file named "tasks.txt".
- Load Tasks: Click the "Load Tasks" button to load tasks from the "tasks.txt" file.
Example Use Cases:
- Run the application and add a few tasks to the list.
- Save the tasks to a file.
- Close the application and run it again.
- Load the saved tasks from the file.
Note: This is a basic implementation and you may want to add more features such as editing tasks, marking tasks as completed, etc.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.