from tkinter import *
from datetime import datetime, timedelta
import pickle
from tkinter import messagebox
filename = "file.pk" #filename data stored as dic = {time:[name,item]}
root = Tk()
t = IntVar()
i = StringVar()
n = StringVar()
def Notification_On_Completing(n, i, t):
return messagebox.showinfo("Completed", "Name:- {}, Item:-{}, in Days:-{}".format(n, i, t))
def Check_If_Time_Is_Over(): #my actual problem is in this function
with open(filename, "rb") as f:
dic = pickle.load(f)
now = datetime.now()
for i, j in dic: #trying to loop and check if the time == now()
if i == now:
Notification_On_Completing(j[0], j[1], i) #if its true return the key which is equal with its value
elif i != now: #if now time i am tryinng to show how much time left
print(i - now, "Time has left for name:-{}, item:-{}".format(j[0],j[1]))
else:
root.after(10000, Check_If_Time_Is_Over)
def SaveTheDaysToNotify():
now = datetime.now()
time = t.get() # days to wait beforer notifying
item = i.get() #item name
name = i.get() #name
end = now + timedelta(days=time) #adding today with the number of days to notify
with open(filename.pk, "rb") as f: # avoiding the overide of the files
dic = pickle.load(f)
dic= {end:[name, item]} # saving a days to notify as dic which will also show the name , and item
with open("file.pk", "wb") as f: #keeping record of the time time to notify
pickle.dump(dic, f)
Check_If_Time_Is_Over()
#Gui starts from here
time1 = Entry(root,textvariable=t).pack() #taking entry as of time, name and item
name1 = Entry(root,textvariable=n).pack()
item1 = Entry(root, textvariable=i).pack()
ss = Button(root,text="done",command=SaveTheDaysToNotify).pack() #adding to the pickle database with format as dictionary as dic ={time:[name, item]}
root.mainloop() Check_If_Time_Is_Over()
I am trying to make a program which will take a entry as Time, item, name.Time will be taken as days to show notification after.For example the program should show the notification after x days and continously checking the if the x days has come even if the program would be closed and reopened for certain times in days or hours interval.