import tkinter as tk
def add_task():
task = entry.get()
if task:
listbox.insert(tk.END, task)
entry.delete(0, tk.END)
def mark_as_complete():
selected = listbox.curselection()
if selected:
listbox.itemconfig(selected, fg="gray")
def remove_task():
selected = listbox.curselection()
if selected:
listbox.delete(selected)
root = tk.Tk()
root.title("To-Do List App")
root.geometry("300x400")
frame = tk.Frame(root)
frame.pack(pady=10)
entry = tk.Entry(frame, width=25)
entry.pack(side=tk.LEFT)
listbox = tk.Listbox(root, width=40, height=15)
listbox.pack(pady=10)
button_frame = tk.Frame(root)
button_frame.pack(pady=5)
add_button = tk.Button(button_frame, text="Add Task", command=add_task)
add_button.pack(side=tk.LEFT, padx=5)
complete_button = tk.Button(button_frame, text="Mark as Complete",
command=mark_as_complete)
complete_button.pack(side=tk.LEFT, padx=5)
remove_button = tk.Button(button_frame, text="Remove Task", command=remove_task)
remove_button.pack(side=tk.LEFT, padx=5)
root.mainloop()
Python с нуля
·
Петр Левашов