-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
109 lines (77 loc) · 2.98 KB
/
Copy pathgui.py
File metadata and controls
109 lines (77 loc) · 2.98 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import customtkinter as ctk
tasks = [] # لیستی برای نگهداری تسکها
def delete_task(task_frame, task_text):
task_frame.destroy()
tasks.remove(task_frame)
# حذف تسک از فایل
with open('tasks.txt', 'r') as file:
lines = file.readlines()
with open('tasks.txt', 'w') as file:
for line in lines:
if line.strip() != task_text:
file.write(line)
def add_task():
task = entry.get().strip()
if not task:
return
with open('tasks.txt', 'r') as task_file:
lines_of_file = [line.strip() for line in task_file.readlines()]
if task in lines_of_file:
print("The task already exists.")
return
with open('tasks.txt', 'a') as task_file:
task_file.write(task + '\n')
task_frame = ctk.CTkFrame(task_list_frame, fg_color='transparent')
task_frame.pack(fill='x', padx=10, pady=2)
task_label = ctk.CTkLabel(task_frame, text=f"• {task}", anchor="w")
task_label.pack(side='left', fill='x', expand=True)
delete_button = ctk.CTkButton(
task_frame,
text="✕",
width=30,
command=lambda frame=task_frame, text=lines: delete_task(frame, text)
)
delete_button.pack(side='right', padx=5)
tasks.append(task_frame)
entry.delete(0, 'end')
# Set appearance and theme
ctk.set_appearance_mode("System") # Options: "Light", "Dark", "System"
ctk.set_default_color_theme("dark-blue") # Options: "blue", "green", "dark-blue"
# Main window
root = ctk.CTk()
root.geometry('400x500')
root.title('To-Do List')
# Main frame
frame = ctk.CTkFrame(root, corner_radius=15)
frame.pack(padx=20, pady=20, fill='both', expand=True)
# Entry for tasks
entry = ctk.CTkEntry(frame, placeholder_text="Enter your task...", width=250)
entry.pack(pady=(20, 10))
# Frame for buttons
button_frame = ctk.CTkFrame(frame, fg_color='transparent')
button_frame.pack(pady=(0, 20))
# Add Button
add_button = ctk.CTkButton(button_frame, text="Add Task", command=add_task)
add_button.pack(side='left', padx=10)
# Scrollable task list area
task_list_container = ctk.CTkScrollableFrame(frame, label_text="Tasks", width=350, height=300, corner_radius=10)
task_list_container.pack(pady=10)
task_list_frame = task_list_container # Alias for clarity
with open('tasks.txt', 'r') as f:
lines = [lines.strip() for lines in f.readlines()]
for line in lines:
task_frame = ctk.CTkFrame(task_list_frame, fg_color='transparent')
task_frame.pack(fill='x', padx=10, pady=2)
task_label = ctk.CTkLabel(task_frame, text=f"• {line}", anchor="w")
task_label.pack(side='left', fill='x', expand=True)
delete_button = ctk.CTkButton(
task_frame,
text="✕",
width=30,
command=lambda frame=task_frame, text=line: delete_task(frame, text)
)
delete_button.pack(side='right', padx=5)
tasks.append(task_frame)
entry.delete(0, 'end')
# Run the app
root.mainloop()