-
Notifications
You must be signed in to change notification settings - Fork 0
/
codsoft_task1.py
210 lines (128 loc) · 4.71 KB
/
codsoft_task1.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#TO_DO_list
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import sqlite3 as sql
def add_task():
task_string = task_field.get()
if len(task_string) == 0:
messagebox.showinfo('Error', 'Field is Empty.')
else:
tasks.append(task_string)
the_cursor.execute('insert into tasks values (?)', (task_string ,))
list_update()
task_field.delete(0, 'end')
def list_update():
clear_list()
for task in tasks:
task_listbox.insert('end', task)
def delete_task():
try:
the_value = task_listbox.get(task_listbox.curselection())
if the_value in tasks:
tasks.remove(the_value)
list_update()
the_cursor.execute('delete from tasks where title = ?', (the_value,))
except:
messagebox.showinfo('Error', 'No Task Selected. Cannot Delete.')
def delete_all_tasks():
message_box = messagebox.askyesno('Delete All', 'Are you sure?')
if message_box == True:
while(len(tasks) != 0):
tasks.pop()
the_cursor.execute('delete from tasks')
list_update()
def clear_list():
task_listbox.delete(0, 'end')
def close():
print(tasks)
guiWindow.destroy()
def retrieve_database():
while(len(tasks) != 0):
tasks.pop()
for row in the_cursor.execute('select title from tasks'):
tasks.append(row[0])
if __name__ == "__main__":
guiWindow = tk.Tk()
guiWindow.title("To-Do List")
guiWindow.geometry("500x450+750+250")
guiWindow.resizable(0, 0)
guiWindow.configure(bg = "#FAEBD7")
the_connection = sql.connect('listOfTasks.db')
the_cursor = the_connection.cursor()
the_cursor.execute('create table if not exists tasks (title text)')
tasks = []
header_frame = tk.Frame(guiWindow, bg = "#FAEBD7")
functions_frame = tk.Frame(guiWindow, bg = "#FAEBD7")
listbox_frame = tk.Frame(guiWindow, bg = "#FAEBD7")
header_frame.pack(fill = "both")
functions_frame.pack(side = "left", expand = True, fill = "both")
listbox_frame.pack(side = "right", expand = True, fill = "both")
header_label = ttk.Label(
header_frame,
text = "To-Do List",
font = ("Brush Script MT", "30"),
background = "#FAEBD7",
foreground = "#8B4513"
)
header_label.pack(padx = 20, pady = 20)
task_label = ttk.Label(
functions_frame,
text = "Enter the Task:",
font = ("Consolas", "11", "bold"),
background = "#FAEBD7",
foreground = "#000000"
)
task_label.place(x = 30, y = 40)
task_field = ttk.Entry(
functions_frame,
font = ("Consolas", "12"),
width = 18,
background = "#FFF8DC",
foreground = "#A52A2A"
)
task_field.place(x = 30, y = 80)
add_button = ttk.Button(
functions_frame,
text = "Add Task",
width = 24,
command = add_task
)
del_button = ttk.Button(
functions_frame,
text = "Delete Task",
width = 24,
command = delete_task
)
del_all_button = ttk.Button(
functions_frame,
text = "Delete All Tasks",
width = 24,
command = delete_all_tasks
)
exit_button = ttk.Button(
functions_frame,
text = "Exit",
width = 24,
command = close
)
add_button.place(x = 30, y = 120)
del_button.place(x = 30, y = 160)
del_all_button.place(x = 30, y = 200)
exit_button.place(x = 30, y = 240)
task_listbox = tk.Listbox(
listbox_frame,
width = 26,
height = 13,
selectmode = 'SINGLE',
background = "#FFFFFF",
foreground = "#000000",
selectbackground = "#CD853F",
selectforeground = "#FFFFFF"
)
task_listbox.place(x = 10, y = 20)
retrieve_database()
list_update()
guiWindow.mainloop()
the_connection.commit()
the_cursor.close()