-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
41 lines (30 loc) · 1.34 KB
/
Copy pathutils.py
File metadata and controls
41 lines (30 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import tkinter as tk
def format_item(task: str, status: str) -> str:
"""Standard display format for listbox items."""
return f"{task} - Status: {status}"
def add_task(entry_task: tk.Entry, entry_status: tk.Entry, listbox: tk.Listbox) -> None:
"""Add a task with status to the listbox and clear the entry fields."""
task = entry_task.get()
status = entry_status.get()
if task and status:
listbox.insert(tk.END, format_item(task, status))
entry_task.delete(0, tk.END)
entry_status.delete(0, tk.END)
def remove_task(listbox: tk.Listbox) -> None:
"""Remove the selected task from the listbox."""
selected_task = listbox.curselection()
if selected_task:
listbox.delete(selected_task)
def update_task(entry_status: tk.Entry, listbox: tk.Listbox) -> None:
"""Update only the status for the selected task."""
selected_task = listbox.curselection()
new_status = entry_status.get()
if selected_task and new_status:
current_text = listbox.get(selected_task)
if " - Status: " in current_text:
task_name = current_text.split(" - Status: ", 1)[0]
else:
task_name = current_text
listbox.delete(selected_task)
listbox.insert(selected_task, format_item(task_name, new_status))
listbox.selection_set(selected_task)