1
1
""" Scientific Calculator made using tkinter module
2
2
Free to copy and open-source """
3
3
4
- from datetime import datetime
5
- from curtsies import Input
4
+ from datetime import datetime , time
5
+ import time
6
6
import webbrowser
7
7
from tkinter import *
8
8
from tkinter import ttk
9
9
from tkinter import messagebox
10
10
import math
11
11
12
12
13
- def main ():
14
- with Input (keynames = 'curses' ) as input_generator :
15
- for e in input_generator :
16
- print (repr (e ))
17
-
18
13
root = Tk ()
19
- root .title ("Second Brain " )
14
+ root .title ("Second Hand " )
20
15
root .resizable (False , False )
21
16
root .eval ('tk::PlaceWindow . center' )
22
17
orig_color = root .cget ("background" )
23
18
root .configure (bg = 'black' )
24
19
25
20
def event_handle (event ):
26
- # Replace the window's title with event.type: input key
27
21
# root.title("{}: {}".format(str(event.type), event.keysym))
28
22
key = event .keysym
29
23
@@ -45,7 +39,7 @@ def event_handle(event):
45
39
tabControl .add (tab1 , text = 'Standard' )
46
40
tabControl .add (tab2 , text = 'Scientific' )
47
41
tabControl .add (tab3 , text = 'Web Browser' )
48
- tabControl .add (tab4 , text = 'Timer ' )
42
+ tabControl .add (tab4 , text = 'Time ' )
49
43
50
44
tabControl .grid (row = 0 , column = 0 )
51
45
@@ -59,8 +53,96 @@ def event_handle(event):
59
53
60
54
tabControl2 .grid (row = 0 , column = 0 )
61
55
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
+
62
66
63
67
"""""" """ 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 """ """"""
64
146
counter = 66600
65
147
running = False
66
148
def counter_label (label ):
@@ -77,17 +159,10 @@ def count():
77
159
display = string
78
160
79
161
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
+
87
163
label .after (1000 , count )
88
164
counter += 1
89
-
90
- # Triggering the start of the counter.
165
+
91
166
count ()
92
167
93
168
# start function of the stopwatch
@@ -122,9 +197,9 @@ def Reset(label):
122
197
label ['text' ]= 'Starting...'
123
198
124
199
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" )
126
201
label .pack ()
127
- f = Frame (tab4 )
202
+ f = Frame (tab_stop_watch )
128
203
start = Button (f , text = 'Start' , width = 6 , command = lambda :Start (label ))
129
204
stop = Button (f , text = 'Stop' ,width = 6 ,state = 'disabled' , command = Stop )
130
205
reset = Button (f , text = 'Reset' ,width = 6 , state = 'disabled' , command = lambda :Reset (label ))
@@ -223,6 +298,7 @@ def dark_mode():
223
298
root .configure (bg = 'black' )
224
299
entry .configure (bg = 'black' , fg = 'white' )
225
300
b .configure (bg = 'black' , fg = 'white' )
301
+ btn .configure (bg = 'black' , fg = 'white' )
226
302
e .configure (bg = "black" , fg = orig_color )
227
303
e_ .configure (bg = "black" , fg = orig_color )
228
304
menubar .configure (bg = 'black' , fg = orig_color )
@@ -286,6 +362,7 @@ def high_contrast_mode():
286
362
root .configure (bg = 'black' )
287
363
entry .configure (bg = 'white' , fg = 'black' )
288
364
b .configure (bg = 'black' , fg = 'white' )
365
+ btn .configure (bg = 'black' , fg = 'white' )
289
366
e .configure (bg = "white" , fg = "black" )
290
367
e_ .configure (bg = "white" , fg = "black" )
291
368
menubar .configure (bg = 'black' , fg = "white" )
@@ -350,6 +427,7 @@ def light_mode():
350
427
s1 .configure ('My.TFrame' , background = "white" )
351
428
entry .configure (bg = 'white' , fg = 'black' )
352
429
b .configure (bg = 'white' , fg = 'black' )
430
+ btn .configure (bg = 'white' , fg = 'black' )
353
431
b2 .configure (bg = 'white' , fg = 'black' )
354
432
e .configure (bg = orig_color , fg = 'black' )
355
433
e_ .configure (bg = orig_color , fg = 'black' )
0 commit comments