Skip to content

Commit 8b5ef19

Browse files
Update second_hand.py
1 parent e909e6b commit 8b5ef19

File tree

1 file changed

+99
-21
lines changed

1 file changed

+99
-21
lines changed

second_hand.py

Lines changed: 99 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
""" Scientific Calculator made using tkinter module
22
Free to copy and open-source """
33

4-
from datetime import datetime
5-
from curtsies import Input
4+
from datetime import datetime, time
5+
import time
66
import webbrowser
77
from tkinter import *
88
from tkinter import ttk
99
from tkinter import messagebox
1010
import math
1111

1212

13-
def main():
14-
with Input(keynames='curses') as input_generator:
15-
for e in input_generator:
16-
print(repr(e))
17-
1813
root = Tk()
19-
root.title("Second Brain")
14+
root.title("Second Hand")
2015
root.resizable(False, False)
2116
root.eval('tk::PlaceWindow . center')
2217
orig_color = root.cget("background")
2318
root.configure(bg='black')
2419

2520
def event_handle(event):
26-
# Replace the window's title with event.type: input key
2721
# root.title("{}: {}".format(str(event.type), event.keysym))
2822
key = event.keysym
2923

@@ -45,7 +39,7 @@ def event_handle(event):
4539
tabControl.add(tab1, text ='Standard')
4640
tabControl.add(tab2, text ='Scientific')
4741
tabControl.add(tab3, text ='Web Browser')
48-
tabControl.add(tab4, text ='Timer')
42+
tabControl.add(tab4, text ='Time')
4943

5044
tabControl.grid(row=0, column=0)
5145

@@ -59,8 +53,96 @@ def event_handle(event):
5953

6054
tabControl2.grid(row=0, column=0)
6155

56+
tabControl3 = ttk.Notebook(tab4)
57+
tab_timer = ttk.Frame(tabControl3, style='My.TFrame')
58+
tab_stop_watch = ttk.Frame(tabControl3, style='My.TFrame')
59+
ttk.Style().configure("TNotebook", background='black');
60+
61+
tabControl3.add(tab_stop_watch, text ='Stop Watch')
62+
tabControl3.add(tab_timer, text ='timer')
63+
64+
tabControl3.grid(row=0, column=0)
65+
6266

6367
""""""""" TIMER """""""""
68+
# Declaration of variables
69+
hour=StringVar()
70+
minute=StringVar()
71+
second=StringVar()
72+
73+
# setting the default value as 0
74+
hour.set("00")
75+
minute.set("00")
76+
second.set("00")
77+
78+
# Use of Entry class to take input from the user
79+
hourEntry= Entry(tab_timer, width=3, font=("Arial",18,""),
80+
textvariable=hour)
81+
hourEntry.place(x=60,y=20)
82+
83+
minuteEntry= Entry(tab_timer, width=3, font=("Arial",18,""),
84+
textvariable=minute)
85+
minuteEntry.place(x=110,y=20)
86+
87+
secondEntry= Entry(tab_timer, width=3, font=("Arial",18,""),
88+
textvariable=second)
89+
secondEntry.place(x=160,y=20)
90+
91+
92+
def submit():
93+
try:
94+
# the input provided by the user is
95+
# stored in here :temp
96+
temp = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())
97+
except:
98+
print("Please input the right value")
99+
while temp >-1:
100+
101+
# divmod(firstvalue = temp//60, secondvalue = temp%60)
102+
mins,secs = divmod(temp,60)
103+
104+
# Converting the input entered in mins or secs to hours,
105+
# mins ,secs(input = 110 min --> 120*60 = 6600 => 1hr :
106+
# 50min: 0sec)
107+
hours=0
108+
if mins >60:
109+
110+
# divmod(firstvalue = temp//60, secondvalue
111+
# = temp%60)
112+
hours, mins = divmod(mins, 60)
113+
114+
# using format () method to store the value up to
115+
# two decimal places
116+
hour.set("{0:2d}".format(hours))
117+
minute.set("{0:2d}".format(mins))
118+
second.set("{0:2d}".format(secs))
119+
120+
# updating the GUI window after decrementing the
121+
# temp value every time
122+
root.update()
123+
time.sleep(1)
124+
125+
# when temp value = 0; then a messagebox pop's up
126+
# with a message:"Time's up"
127+
if (temp == 0):
128+
messagebox.showinfo("Time Countdown", "Time's up ")
129+
130+
# after every one sec the value of temp will be decremented
131+
# by one
132+
temp -= 1
133+
134+
# button widget
135+
btn = Button(tab_timer , text='Set Time Countdown', bd='2',
136+
command= submit)
137+
btn.place(x = 30,y = 60)
138+
139+
# infinite loop which is required to
140+
# run tkinter program infinitely
141+
# until an interrupt occurs
142+
143+
144+
145+
""""""""" STOP WATCH """""""""
64146
counter = 66600
65147
running = False
66148
def counter_label(label):
@@ -77,17 +159,10 @@ def count():
77159
display=string
78160

79161
label['text']=display # Or label.config(text=display)
80-
81-
# label.after(arg1, arg2) delays by
82-
# first argument given in milliseconds
83-
# and then calls the function given as second argument.
84-
# Generally like here we need to call the
85-
# function in which it is present repeatedly.
86-
# Delays by 1000ms=1 seconds and call count again.
162+
87163
label.after(1000, count)
88164
counter += 1
89-
90-
# Triggering the start of the counter.
165+
91166
count()
92167

93168
# start function of the stopwatch
@@ -122,9 +197,9 @@ def Reset(label):
122197
label['text']='Starting...'
123198

124199

125-
label = Label(tab4, text="Welcome!", fg="black", font="Verdana 30 bold")
200+
label = Label(tab_stop_watch, text="Welcome!", fg="black", font="Verdana 30 bold")
126201
label.pack()
127-
f = Frame(tab4)
202+
f = Frame(tab_stop_watch)
128203
start = Button(f, text='Start', width=6, command=lambda:Start(label))
129204
stop = Button(f, text='Stop',width=6,state='disabled', command=Stop)
130205
reset = Button(f, text='Reset',width=6, state='disabled', command=lambda:Reset(label))
@@ -223,6 +298,7 @@ def dark_mode():
223298
root.configure(bg='black')
224299
entry.configure(bg='black', fg='white')
225300
b.configure(bg='black', fg='white')
301+
btn.configure(bg='black', fg='white')
226302
e.configure(bg="black", fg=orig_color)
227303
e_.configure(bg="black", fg=orig_color)
228304
menubar.configure(bg='black', fg=orig_color)
@@ -286,6 +362,7 @@ def high_contrast_mode():
286362
root.configure(bg='black')
287363
entry.configure(bg='white', fg='black')
288364
b.configure(bg='black', fg='white')
365+
btn.configure(bg='black', fg='white')
289366
e.configure(bg="white", fg="black")
290367
e_.configure(bg="white", fg="black")
291368
menubar.configure(bg='black', fg="white")
@@ -350,6 +427,7 @@ def light_mode():
350427
s1.configure('My.TFrame', background="white")
351428
entry.configure(bg='white', fg='black')
352429
b.configure(bg='white', fg='black')
430+
btn.configure(bg='white', fg='black')
353431
b2.configure(bg='white', fg='black')
354432
e.configure(bg=orig_color, fg='black')
355433
e_.configure(bg=orig_color, fg='black')

0 commit comments

Comments
 (0)