-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount.py
118 lines (107 loc) · 3.6 KB
/
count.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
#Countdown from specified date and time.
#Known bugs have been specified in the file bugs.txt
import Tkinter
from datetime import date
from datetime import datetime
class Count_app(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent=parent
self.initialize()
def initialize(self):
menuBar= Tkinter.Menu(self, relief="flat")
FileMenu=Tkinter.Menu(menuBar, tearoff=0)
FileMenu.add_command(label="New Count",command=self.new)
FileMenu.add_separator()
FileMenu.add_command(label="Save data",command=self.save)
FileMenu.add_command(label="Load Count",command=self.load)
FileMenu.add_separator()
FileMenu.add_command(label="Exit",command=self.quit)
HelpMenu=Tkinter.Menu(menuBar,tearoff=0)
HelpMenu.add_command(label="About",command=self.about)
menuBar.add_cascade(label="File", menu=FileMenu)
menuBar.add_cascade(label="Help", menu=HelpMenu)
self.config(menu=menuBar)
self.resizable(False,False)
def new(self):
self.f1=Tkinter.Frame(self)
self.f1.pack(anchor="w")
nameLabel=Tkinter.Label(self.f1,anchor="w",text="Name of event: ")
nameLabel.pack(anchor="w",side="top",pady=10)
self.name=Tkinter.StringVar()
nameEntry=Tkinter.Entry(self.f1,textvariable=self.name,width=30)
nameEntry.pack(anchor="w")
STLabel=Tkinter.Label(self.f1,text="Event Date(dd mm yyyy): ")
STLabel.pack(anchor="w",side="top",pady=10)
self.STime=Tkinter.StringVar()
STEntry=Tkinter.Entry(self.f1,textvariable=self.STime,width=30)
STEntry.pack(anchor="w")
button=Tkinter.Button(self.f1,text=u"Launch Countdown",command=self.OnClick)
button.pack(side="top",pady=10)
def OnClick(self):
try:
errorVar=Tkinter.StringVar()
errorVar.set("")
errorLabel=Tkinter.Label(self,anchor="center",textvariable=errorVar)
errorLabel.pack(side="top",pady=10)
setTime=list(map(int,self.STime.get().split()))
self.f1.destroy()
self.f1=Tkinter.Frame(self)
self.f1.pack(anchor="w")
eventName=self.name.get()
Title=Tkinter.Label(self.f1,anchor="center",text="\tTime left for "+eventName)
Title.pack()
count=Tkinter.StringVar()
countLabel=Tkinter.Label(self.f1,anchor="center",textvariable=count)
countLabel.pack(side="top",pady=30)
def update_label():
count.set(self.getCount(setTime))
countLabel.after(1000,update_label)
update_label()
except ValueError:
errorVar.set("Invalid Input") #How to delete this label when correct val given is a problem
self.f1.destroy()
self.new()
def getCount(self,setTime):
'''
Calculates the time left
'''
curTime=datetime.now()
b=datetime.today().date()
a=date(setTime[2],setTime[1],setTime[0])
sec=60-curTime.second
minute=59-curTime.minute
hour=23-curTime.hour
res="\t"+str((a-b).days-1)+" days, "+str(hour)+" hours, "+str(minute)+" minutes, "+str(sec)+" seconds."
return str(res)
def save(self):
'''
Save the data pertaining to the name of event and date set so that user
can load this data and get the counter running easily.
'''
#To be implemented
pass
def load(self):
'''
Load a previously saved counter for a date and event.
This should contain data for some popular awaited events such as new year etc.
'''
#To be implemented
pass
def about(self):
AboutText="""
About
Countdown v1.0
Written by Abhinav Dhere. This software is open sourced
as per the MIT License provided in the file LICENSE.
"""
newWin=Tkinter.Toplevel()
newWin.title("About")
newWin.geometry("480x240",)
aboutlab=Tkinter.Label(newWin,text=AboutText)
aboutlab.pack()
if __name__=="__main__":
app=Count_app(None)
app.title("Countdown")
app.geometry("350x270+1050+0")
app.mainloop()