-
Notifications
You must be signed in to change notification settings - Fork 0
/
planner.py
104 lines (82 loc) · 2.58 KB
/
planner.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
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
from tkcalendar import Calendar, DateEntry
import sqlite3 as sq
root = tk.Tk()
root.title('Planner')
root.geometry("530x300+500+500")
# Making a database file called "planner.db"
conn = sq.connect('PlannerDB.db')
# The database will be saved in the location where your 'py' file is saved
cur = conn.cursor()
# Create table - PLANNER
cur.execute('''CREATE TABLE IF NOT EXISTS PLANNER
([Tasks] text, [Date] date)''')
task = []
# clear tkinter listbox
def clearList():
t.delete(0,'end')
def addTask():
word = e1.get()
date = cal.get_date()
rows = [(word, date)]
if len(word)==0:
messagebox.showinfo('Empty Entry', 'Enter task name')
elif l1.cget("text")=="":
messagebox.showinfo('Empty Entry', 'Enter date')
else:
task.append(word)
cur.executemany('INSERT INTO PLANNER VALUES (?, ?)', rows)
selectDate()
e1.delete(0,'end')
# If the value you delete exists then it also gets deleted on any dates.
def delOne():
try:
val = t.get(t.curselection())
cur.execute('DELETE FROM PLANNER WHERE Tasks = (?)', (val,))
selectDate()
except:
messagebox.showinfo('Cannot Delete', 'No Task Item Selected')
def deleteAll():
mb = messagebox.askyesno('Delete All','Are you sure?')
date = cal.get_date()
if mb==True:
cur.execute('DELETE FROM PLANNER WHERE Date = (?)', (date,))
selectDate()
def bye():
root.destroy()
def selectDate():
l1["text"] = cal.get_date()
clearList()
cur.execute("SELECT * FROM PLANNER")
values = []
for val in cur:
if (str(cal.get_date()) == val[1]):
values.append(val[0])
for i in values:
t.insert("end", i)
l1 = ttk.Label(root, text="")
l1.place(x=370 ,y=30)
l2 = ttk.Label(root, text='Enter down below')
e1 = ttk.Entry(root, width=21)
t = tk.Listbox(root, height=11, selectmode='SINGLE')
b1 = ttk.Button(root, text='Add task', width=20, command=addTask)
b2 = ttk.Button(root, text='Delete', width=20, command=delOne)
b3 = ttk.Button(root, text='Delete all', width=20, command=deleteAll)
b4 = ttk.Button(root, text='Exit', width=20, command=bye)
b5 = ttk.Button(root, text='Select', width=20, command=selectDate)
cal = DateEntry(root, width=30, bg="darkblue", fg="black", year=2021)
cal.grid()
#Place geometry
l2.place(x=90, y=50)
e1.place(x=50, y=80)
b1.place(x=40, y=110)
b2.place(x=40, y=140)
b3.place(x=40, y=170)
b4.place(x=40, y =200)
b5.place(x=300, y=0)
t.place(x=320, y=50)
root.mainloop()
conn.commit()
cur.close()