Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox
- # Initialize the window
- window = tk.Tk()
- window.title("To-Do List")
- # Create a list to store tasks
- tasks = []
- # Function to add a task
- def add_task():
- task = entry.get()
- if task:
- tasks.append(task)
- update_task_list()
- entry.delete(0, tk.END)
- else:
- messagebox.showwarning("Empty Task", "Please enter a task.")
- # Function to remove a task
- def remove_task():
- selected_task = task_listbox.curselection()
- if selected_task:
- index = selected_task[0]
- tasks.pop(index)
- update_task_list()
- # Function to update the task list
- def update_task_list():
- task_listbox.delete(0, tk.END)
- for task in tasks:
- task_listbox.insert(tk.END, task)
- # Entry widget to input tasks
- entry = tk.Entry(window, width=30)
- entry.grid(row=0, column=0, padx=10, pady=10)
- # Button to add a task
- add_button = tk.Button(window, text="Add Task", command=add_task)
- add_button.grid(row=0, column=1, padx=5)
- # Task listbox
- task_listbox = tk.Listbox(window, width=40)
- task_listbox.grid(row=1, column=0, columnspan=2, padx=10, pady=10)
- # Button to remove a task
- remove_button = tk.Button(window, text="Remove Task", command=remove_task)
- remove_button.grid(row=2, column=0, columnspan=2, padx=10, pady=5)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement