-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_hand.py
More file actions
1086 lines (866 loc) · 36.1 KB
/
second_hand.py
File metadata and controls
1086 lines (866 loc) · 36.1 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
""" Scientific Calculator made using tkinter module
Free to copy and open-source """
from datetime import datetime, time
import time
import webbrowser
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import math
root = Tk()
root.title("Second Hand")
root.resizable(False, False)
root.eval('tk::PlaceWindow . center')
orig_color = root.cget("background")
root.configure(bg='black')
def event_handle(event):
# root.title("{}: {}".format(str(event.type), event.keysym))
key = event.keysym
s1 = ttk.Style()
s1.configure('My.TFrame', background='black')
tabControl = ttk.Notebook(root)
tab1 = ttk.Frame(tabControl, style='My.TFrame')
tab2 = ttk.Frame(tabControl, style='My.TFrame')
tab3 = ttk.Frame(tabControl, style='My.TFrame')
tab4 = ttk.Frame(tabControl, style='My.TFrame')
ttk.Style().configure("TNotebook", background='black');
tabControl.add(tab1, text ='Standard')
tabControl.add(tab2, text ='Scientific')
tabControl.add(tab3, text ='Web Browser')
tabControl.add(tab4, text ='Time')
tabControl.grid(row=0, column=0)
tabControl2 = ttk.Notebook(tab3)
tab_link = ttk.Frame(tabControl2, style='My.TFrame')
tab_url = ttk.Frame(tabControl2, style='My.TFrame')
ttk.Style().configure("TNotebook", background='black');
tabControl2.add(tab_url, text ='Custom URL')
tabControl2.add(tab_link, text ='Quick Links')
tabControl2.grid(row=0, column=0)
tabControl3 = ttk.Notebook(tab4)
tab_timer = ttk.Frame(tabControl3, style='My.TFrame')
tab_stop_watch = ttk.Frame(tabControl3, style='My.TFrame')
ttk.Style().configure("TNotebook", background='black');
tabControl3.add(tab_stop_watch, text ='Stop Watch')
tabControl3.add(tab_timer, text ='timer')
tabControl3.grid(row=0, column=0)
""""""""" TIMER """""""""
# Declaration of variables
hour=StringVar()
minute=StringVar()
second=StringVar()
# setting the default value as 0
hour.set("00")
minute.set("00")
second.set("00")
# Use of Entry class to take input from the user
hourEntry= Entry(tab_timer, width=3, font=("Arial",18,""),
textvariable=hour)
hourEntry.place(x=60,y=20)
minuteEntry= Entry(tab_timer, width=3, font=("Arial",18,""),
textvariable=minute)
minuteEntry.place(x=110,y=20)
secondEntry= Entry(tab_timer, width=3, font=("Arial",18,""),
textvariable=second)
secondEntry.place(x=160,y=20)
def submit():
try:
# the input provided by the user is
# stored in here :temp
temp = int(hour.get())*3600 + int(minute.get())*60 + int(second.get())
except:
print("Please input the right value")
while temp >-1:
# divmod(firstvalue = temp//60, secondvalue = temp%60)
mins,secs = divmod(temp,60)
# Converting the input entered in mins or secs to hours,
# mins ,secs(input = 110 min --> 120*60 = 6600 => 1hr :
# 50min: 0sec)
hours=0
if mins >60:
# divmod(firstvalue = temp//60, secondvalue
# = temp%60)
hours, mins = divmod(mins, 60)
# using format () method to store the value up to
# two decimal places
hour.set("{0:2d}".format(hours))
minute.set("{0:2d}".format(mins))
second.set("{0:2d}".format(secs))
# updating the GUI window after decrementing the
# temp value every time
root.update()
time.sleep(1)
# when temp value = 0; then a messagebox pop's up
# with a message:"Time's up"
if (temp == 0):
messagebox.showinfo("Time Countdown", "Time's up ")
# after every one sec the value of temp will be decremented
# by one
temp -= 1
# button widget
btn = Button(tab_timer , text='Set Time Countdown', bd='2',
command= submit)
btn.place(x = 30,y = 60)
""""""""" STOP WATCH """""""""
counter = 66600
running = False
def counter_label(label):
def count():
if running:
global counter
# To manage the initial delay.
if counter==66600:
display="Starting..."
else:
tt = datetime.fromtimestamp(counter)
string = tt.strftime("%H:%M:%S")
display=string
label['text']=display # Or label.config(text=display)
label.after(1000, count)
counter += 1
count()
# start function of the stopwatch
def Start(label):
global running
running=True
counter_label(label)
start['state']='disabled'
stop['state']='normal'
reset['state']='normal'
# Stop function of the stopwatch
def Stop():
global running
start['state']='normal'
stop['state']='disabled'
reset['state']='normal'
running = False
# Reset function of the stopwatch
def Reset(label):
global counter
counter=66600
# If rest is pressed after pressing stop.
if running==False:
reset['state']='disabled'
label['text']='Welcome!'
# If reset is pressed while the stopwatch is running.
else:
label['text']='Starting...'
label = Label(tab_stop_watch, text="Welcome!", fg="black", font="Verdana 30 bold")
label.pack()
f = Frame(tab_stop_watch)
start = Button(f, text='Start', width=6, command=lambda:Start(label))
stop = Button(f, text='Stop',width=6,state='disabled', command=Stop)
reset = Button(f, text='Reset',width=6, state='disabled', command=lambda:Reset(label))
f.pack(anchor = 'center',pady=5)
start.pack(side="left")
stop.pack(side ="left")
reset.pack(side="left")
""""""""" WEB """""""""
def open_page():
webbrowser.open(entry.get())
def entry_delete():
entry.delete(0, END)
def whaturl():
webbrowser.open(url)
def custom_quick_link():
global url
global urlwhat
global quick_link_entry
global quick_link_name
custom_quick = Toplevel(root)
quick_link_entry_url = Label(custom_quick, text='Enter URL :- ').grid(row=0, column=0)
quick_link_entry = Entry(custom_quick)
url = quick_link_entry.get()
quick_link_entry.insert(0, "")
urlwhat = quick_link_entry.get()
quick_link_entry.grid(row=0, column=1)
quick_link_entry_name = Label(custom_quick, text='Enter Name :- ').grid(row=1, column=0)
quick_link_name = Entry(custom_quick)
quick_link_name.grid(row=1, column=1)
quick_link_button = Button(custom_quick, text="Use link", command=custom_quick_link_add).grid(row=2, column=0)
def custom_quick_link_add():
if quick_link_entry.get() == "":
error = messagebox.askokcancel("ERROR ", "Please Enter URL")
if error == True:
pass
else:
root.quit()
else:
# url = quick_link_entry.get()
name = quick_link_name.get()
Button(tab_link, text=name, command=webbrowser.open(quick_link_entry.get()).pack(side=RIGHT))
web_what = Label(tab_url, text="Enter a URL above to open it in your fav browsers")
web_what.grid(row=4, column=0, columnspan=15)
entry = Entry(tab_url, width=50)
entry.insert(0, "")
entry.grid(row=2, column=0, columnspan=15)
b = Button(tab_url, text='GO TO URL', command=open_page)
b.grid(row=3, column=0)
b2 = Button(tab_url, text='clear', command=entry_delete)
b2.grid(row=3, column=1)
quick_links = Button(tab_link, text="Custom Quick Links", command=custom_quick_link)
quick_links.pack() #grid(row=3, column=2)
def github():
webbrowser.open('www.github.com')
def linux_mint():
webbrowser.open('www.linuxmint.com')
link1 = Button(tab_link, text="Github", command=github)
link1.pack() #(row=4, column=0)
link2 = Button(tab_link, text="linux mint", command=linux_mint)
link2.pack() #(row=4, column=1)
""""""""" Calculator """""""""
e = Entry(tab1, width=35, borderwidth=5)
e.grid(row=1, column=0, columnspan=10, padx=5, pady=5)
e_ = Entry(tab2, width=35, borderwidth=5)
e_.grid(row=1, column=0, columnspan=5, padx=5, pady=5)
e.configure(bg="white", fg='black')
e_.configure(bg="white", fg="black")
def dark_mode():
ttk.Style().configure("TNotebook", background='black');
s1.configure('My.TFrame', background='black')
root.configure(bg='black')
entry.configure(bg='black', fg='white')
b.configure(bg='black', fg='white')
btn.configure(bg='black', fg='white')
e.configure(bg="black", fg=orig_color)
e_.configure(bg="black", fg=orig_color)
menubar.configure(bg='black', fg=orig_color)
aboutmenu.configure(bg="black", fg=orig_color)
settingsmenu.configure(bg="black", fg=orig_color)
editmenu.configure(bg="black", fg=orig_color)
Button_0.configure(bg="black", fg=orig_color)
Button_1.configure(bg="black", fg=orig_color)
Button_2.configure(bg="black", fg=orig_color)
Button_3.configure(bg="black", fg=orig_color)
Button_4.configure(bg="black", fg=orig_color)
Button_5.configure(bg="black", fg=orig_color)
Button_6.configure(bg="black", fg=orig_color)
Button_7.configure(bg="black", fg=orig_color)
Button_8.configure(bg="black", fg=orig_color)
Button_9.configure(bg="black", fg=orig_color)
Button_add.configure(bg="black", fg=orig_color)
Button_subtract.configure(bg="black", fg=orig_color)
Button_divide.configure(bg="black", fg=orig_color)
Button_multiply.configure(bg="black", fg=orig_color)
Button_open_paranthesis.configure(bg="black", fg=orig_color)
Button_close_paranthesis.configure(bg="black", fg=orig_color)
Button_equal.configure(bg="black", fg=orig_color)
Button_exit.configure(bg="black", fg=orig_color)
Button_pi_.configure(bg="black", fg=orig_color)
Button_sqr_.configure(bg="black", fg=orig_color)
Button_sqrt_.configure(bg="black", fg=orig_color)
Button_remainder_.configure(bg="black", fg=orig_color)
Button_power_.configure(bg="black", fg=orig_color)
Button_point.configure(bg="black", fg=orig_color)
Button_clear.configure(bg="black", fg=orig_color)
Button_fact_.configure(bg="black", fg=orig_color)
Button_undo.configure(bg="black", fg=orig_color)
Button_undo_.configure(bg="black", fg=orig_color)
Button_0_.configure(bg="black", fg=orig_color)
Button_1_.configure(bg="black", fg=orig_color)
Button_2_.configure(bg="black", fg=orig_color)
Button_3_.configure(bg="black", fg=orig_color)
Button_4_.configure(bg="black", fg=orig_color)
Button_5_.configure(bg="black", fg=orig_color)
Button_6_.configure(bg="black", fg=orig_color)
Button_7_.configure(bg="black", fg=orig_color)
Button_8_.configure(bg="black", fg=orig_color)
Button_9_.configure(bg="black", fg=orig_color)
Button_add_.configure(bg="black", fg=orig_color)
Button_subtract_.configure(bg="black", fg=orig_color)
Button_divide_.configure(bg="black", fg=orig_color)
Button_multiply_.configure(bg="black", fg=orig_color)
Button_open_paranthesis_.configure(bg="black", fg=orig_color)
Button_close_paranthesis_.configure(bg="black", fg=orig_color)
Button_equal_.configure(bg="black", fg=orig_color)
Button_exit_.configure(bg="black", fg=orig_color)
Button_point_.configure(bg="black", fg=orig_color)
Button_clear_.configure(bg="black", fg=orig_color)
def high_contrast_mode():
ttk.Style().configure("TNotebook", background='black');
s1.configure('My.TFrame', background='black')
root.configure(bg='black')
entry.configure(bg='white', fg='black')
b.configure(bg='black', fg='white')
btn.configure(bg='black', fg='white')
e.configure(bg="white", fg="black")
e_.configure(bg="white", fg="black")
menubar.configure(bg='black', fg="white")
aboutmenu.configure(bg="black", fg="white")
settingsmenu.configure(bg="black", fg="white")
editmenu.configure(bg="black", fg="white")
Button_0.configure(bg="grey", fg="white")
Button_1.configure(bg="grey", fg="white")
Button_2.configure(bg="grey", fg="white")
Button_3.configure(bg="grey", fg="white")
Button_4.configure(bg="grey", fg="white")
Button_5.configure(bg="grey", fg="white")
Button_6.configure(bg="grey", fg="white")
Button_7.configure(bg="grey", fg="white")
Button_8.configure(bg="grey", fg="white")
Button_9.configure(bg="grey", fg="white")
Button_add.configure(bg="brown", fg="white")
Button_subtract.configure(bg="brown", fg="white")
Button_divide.configure(bg="brown", fg="white")
Button_multiply.configure(bg="brown", fg="white")
Button_open_paranthesis.configure(bg="black", fg="white")
Button_close_paranthesis.configure(bg="black", fg="white")
Button_equal.configure(bg="orange", fg="white")
Button_exit.configure(bg="black", fg="white")
Button_pi_.configure(bg="indigo", fg="white")
Button_sqr_.configure(bg="indigo", fg="white")
Button_sqrt_.configure(bg="indigo", fg="white")
Button_remainder_.configure(bg="indigo", fg="white")
Button_power_.configure(bg="indigo", fg="white")
Button_point.configure(bg="grey", fg="white")
Button_clear.configure(bg="black", fg="white")
Button_fact_.configure(bg="indigo", fg="white")
Button_undo.configure(bg="black", fg="white")
Button_undo_.configure(bg="black", fg="white")
Button_0_.configure(bg="grey", fg="white")
Button_1_.configure(bg="grey", fg="white")
Button_2_.configure(bg="grey", fg="white")
Button_3_.configure(bg="grey", fg="white")
Button_4_.configure(bg="grey", fg="white")
Button_5_.configure(bg="grey", fg="white")
Button_6_.configure(bg="grey", fg="white")
Button_7_.configure(bg="grey", fg="white")
Button_8_.configure(bg="grey", fg="white")
Button_9_.configure(bg="grey", fg="white")
Button_add_.configure(bg="brown", fg="white")
Button_subtract_.configure(bg="brown", fg="white")
Button_divide_.configure(bg="brown", fg="white")
Button_multiply_.configure(bg="brown", fg="white")
Button_open_paranthesis_.configure(bg="black", fg="white")
Button_close_paranthesis_.configure(bg="black", fg="white")
Button_equal_.configure(bg="orange", fg="white")
Button_exit_.configure(bg="black", fg="white")
Button_point_.configure(bg="grey", fg="white")
Button_clear_.configure(bg="black", fg="white")
def light_mode():
ttk.Style().configure("TNotebook", background="white");
s1.configure('My.TFrame', background="white")
entry.configure(bg='white', fg='black')
b.configure(bg='white', fg='black')
btn.configure(bg='white', fg='black')
b2.configure(bg='white', fg='black')
e.configure(bg=orig_color, fg='black')
e_.configure(bg=orig_color, fg='black')
menubar.configure(bg="white", fg="black")
aboutmenu.configure(bg="white", fg="black")
settingsmenu.configure(bg="white", fg="black")
editmenu.configure(bg="white", fg="black")
Button_0.configure(bg="white", fg="black")
Button_1.configure(bg="white", fg="black")
Button_2.configure(bg="white", fg="black")
Button_3.configure(bg="white", fg="black")
Button_4.configure(bg="white", fg="black")
Button_5.configure(bg="white", fg="black")
Button_6.configure(bg="white", fg="black")
Button_7.configure(bg="white", fg="black")
Button_8.configure(bg="white", fg="black")
Button_9.configure(bg="white", fg="black")
Button_add.configure(bg="white", fg="black")
Button_subtract.configure(bg="white", fg="black")
Button_divide.configure(bg="white", fg="black")
Button_multiply.configure(bg="white", fg="black")
Button_open_paranthesis.configure(bg="white", fg="black")
Button_close_paranthesis.configure(bg="white", fg="black")
Button_equal.configure(bg="white", fg="black")
Button_exit.configure(bg="white", fg="black")
Button_pi_.configure(bg="white", fg="black")
Button_sqr_.configure(bg="white", fg="black")
Button_sqrt_.configure(bg="white", fg="black")
Button_remainder_.configure(bg="white", fg="black")
Button_power_.configure(bg="white", fg="black")
Button_point.configure(bg="white", fg="black")
Button_clear.configure(bg="white", fg="black")
Button_fact_.configure(bg="white", fg="black")
Button_undo.configure(bg="white", fg="black")
Button_undo_.configure(bg="white", fg="black")
Button_0_.configure(bg="white", fg="black")
Button_1_.configure(bg="white", fg="black")
Button_2_.configure(bg="white", fg="black")
Button_3_.configure(bg="white", fg="black")
Button_4_.configure(bg="white", fg="black")
Button_5_.configure(bg="white", fg="black")
Button_6_.configure(bg="white", fg="black")
Button_7_.configure(bg="white", fg="black")
Button_8_.configure(bg="white", fg="black")
Button_9_.configure(bg="white", fg="black")
Button_add_.configure(bg="white", fg="black")
Button_subtract_.configure(bg="white", fg="black")
Button_divide_.configure(bg="white", fg="black")
Button_multiply_.configure(bg="white", fg="black")
Button_open_paranthesis_.configure(bg="white", fg="black")
Button_close_paranthesis_.configure(bg="white", fg="black")
Button_equal_.configure(bg="white", fg="black")
Button_point_.configure(bg="white", fg="black")
Button_exit_.configure(bg="white", fg="black")
Button_clear_.configure(bg="white", fg="black")
def button_exit():
root.quit()
def button_exit_():
root.quit()
def about_menu():
about = Toplevel(root)
about.geometry("320x280+0+0")
label1 = Label(about, text="Developed By Srikara under open source licence").grid(row=0, column=1)
label2 = Label(about, text="Date:- 19.11.2021").grid(row=1, column=1)
label3 = Label(about, text="Made in Python using tkinter module").grid(row=2, column=1)
root.eval(f'tk::PlaceWindow {str(about)} center')
menubar = Menu(root)
# ManuBar 1 :
filemenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label = 'Mode', menu = filemenu)
filemenu.add_command(label = "Exit", command = button_exit)
editmenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label = 'Edit', menu = editmenu)
editmenu.add_command(label = "Cut")
editmenu.add_command(label = "Copy")
editmenu.add_separator()
editmenu.add_command(label = "Paste")
aboutmenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label = 'About', menu = aboutmenu)
aboutmenu.add_command(label = "About", command = about_menu)
aboutmenu.add_command(label = "Contribute")
aboutmenu.add_command(label = "Help")
aboutmenu.add_separator()
settingsmenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label = 'Settings', menu = settingsmenu)
settingsmenu.add_command(label = "Light Theme", command = light_mode)
settingsmenu.add_command(label = "Dark Theme", command = dark_mode)
settingsmenu.add_command(label = "High Contrast", command = high_contrast_mode)
root.config(menu=menubar)
menubar.configure(bg="black", fg="white")
aboutmenu.configure(bg="black", fg="white")
settingsmenu.configure(bg="black", fg="white")
editmenu.configure(bg="black", fg="white")
def button_click(number):
current = e.get()
e.delete(0, END)
e.insert(0, str(current) + str(number))
current = e_.get()
e_.delete(0, END)
e_.insert(0, str(current) + str(number))
check_add = "mylabel_add" in globals()
check_pi = "mylabel_pi" in globals()
check_sub = "mylabel_sub" in globals()
check_mult = "mylabel_mult" in globals()
check_div = "mylabel_div" in globals()
check_rem = "mylabel_rem" in globals()
check_pow = "mylabel_pow" in globals()
check_sqr = "mylabel_sqr" in globals()
check_sqrt = "mylabel_sqrt" in globals()
check_fact = "mylabel_fact" in globals()
if check_add == True:
mylabel_add.destroy()
if check_sub == True:
mylabel_sub.destroy()
if check_mult == True:
mylabel_mult.destroy()
if check_div == True:
mylabel_div.destroy()
if check_rem == True:
mylabel_rem.destroy()
if check_pow == True:
mylabel_pow.destroy()
if check_sqr == True:
mylabel_sqr.destroy()
if check_pi == True:
mylabel_pi.destroy()
if check_sqrt == True:
mylabel_sqrt.destroy()
if check_fact == True:
mylabel_fact.destroy()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def button_click_(number):
global current
current = e_.get()
e_.delete(0, END)
e_.insert(0, str(current) + str(number))
check_add = "mylabel_add" in globals()
check_pi = "mylabel_pi" in globals()
check_sub = "mylabel_sub" in globals()
check_mult = "mylabel_mult" in globals()
check_div = "mylabel_div" in globals()
check_rem = "mylabel_rem" in globals()
check_pow = "mylabel_pow" in globals()
check_sqr = "mylabel_sqr" in globals()
check_sqrt = "mylabel_sqrt" in globals()
check_fact = "mylabel_fact" in globals()
if check_add == True:
mylabel_add.destroy()
if check_sub == True:
mylabel_sub.destroy()
if check_mult == True:
mylabel_mult.destroy()
if check_div == True:
mylabel_div.destroy()
if check_rem == True:
mylabel_rem.destroy()
if check_pow == True:
mylabel_pow.destroy()
if check_sqr == True:
mylabel_sqr.destroy()
if check_pi == True:
mylabel_pi.destroy()
if check_sqrt == True:
mylabel_sqrt.destroy()
if check_fact == True:
mylabel_fact.destroy()
def undo_last():
e.delete(len(e.get())-1,END)
def undo_last_():
e_.delete(len(e_.get())-1,END)
def button_clear():
e.delete(0, END)
def button_clear_():
e_.delete(0, END)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def button_equal():
try:
result_add = e.get().find("+")
result_sub = e.get().find("-")
result_mult = e.get().find("*")
result_div = e.get().find("/")
if result_add >= 0:
global add1
add1 = e.get()
add = eval(e.get())
e.delete(0, END)
e_.delete(0, END)
e.insert(0, add)
whatfunction_add()
if result_sub >= 0:
global sub1
sub1 = e.get()
sub = eval(e.get())
e.delete(0, END)
e_.delete(0, END)
e.insert(0, sub)
whatfunction_sub()
if result_mult >= 0:
global mult1
mult1 = e.get()
mult = eval(e.get())
e.delete(0, END)
e_.delete(0, END)
e.insert(0, mult)
whatfunction_mult()
if result_div >= 0:
global div1
div1 = e.get()
div = eval(e.get())
e.delete(0, END)
e_.delete(0, END)
e.insert(0, div)
whatfunction_div()
except NameError:
error = messagebox.askokcancel("Name Error ", "Please Enter an valid expression")
if error == True:
pass
else:
root.quit()
except ValueError:
error2 = messagebox.askokcancel("Value Error ", "Enter an valid expression !")
if error2 == True:
pass
else:
root.quit()
except ZeroDivisionError:
error3 = messagebox.askokcancel("Value Error ", "Did u learn maths ? you can't divide zero")
if error3 == True:
pass
else:
root.quit()
except SyntaxError:
error3 = messagebox.askokcancel("Value Error ", "Did u learn maths ?")
if error3 == True:
pass
else:
root.quit()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def button_equal_():
global second_number
global myerrorlabel
result_add = e_.get().find("+")
result_sub = e_.get().find("-")
result_mult = e_.get().find("*")
result_div = e_.get().find("/")
result_rem = e_.get().find("%")
result_pow = e_.get().find("**")
result_sqr = e_.get().find("* 2")
result_pi = e_.get().find("3.141592653589793")
result_sqrt = e_.get().find("sqrt")
result_fact = e_.get().find("fact")
try:
global power_what
power_what = e_.get()
if result_add >= 0:
global add2
add2 = e_.get()
add = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, add)
whatfunction_add_()
if result_sub >= 0:
global sub2
sub2 = e_.get()
sub = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, sub)
whatfunction_sub_()
if result_mult >= 0:
global mult2
mult2 = e_.get()
mult = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, mult)
whatfunction_mult_()
if result_div >= 0:
global div2
div2 = e_.get()
div = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, div)
whatfunction_div_()
if result_rem >= 0:
global rem2
rem2 = e_.get()
rem = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, rem)
whatfunction_rem()
if result_pow >= 0:
pow1 = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, pow1)
whatfunction_pow()
if result_sqr >= 0:
global sqr2
sqr2 = e_.get()
sqr = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, sqr)
whatfunction_sqr()
if result_pi >= 0:
global pi2
pi2 = e_.get()
pi = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, pi)
whatfunction_pi()
if result_sqrt >= 0:
global sqrt2
sqrt2 = e_.get()
sqrt = eval(e_.get())
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, sqrt)
whatfunction_sqrt()
if result_fact >= 0:
global fact2
fact2 = e_.get()
fact = e_.get()
facto = int ( ''.join(filter(str.isdigit, fact) ) )
e_.delete(0, END)
e.delete(0, END)
e_.insert(0, math.factorial(facto))
whatfunction_fact()
except NameError:
error = messagebox.askokcancel("Name Error ", "Please Enter an valid expression")
if error == True:
pass
else:
root.quit()
except ValueError:
error2 = messagebox.askokcancel("Value Error ", "Enter an valid expression !")
if error2 == True:
pass
else:
root.quit()
except ZeroDivisionError:
error3 = messagebox.askokcancel("Value Error ", "Did u learn maths ? you can't divide zero")
if error3 == True:
pass
else:
root.quit()
except SyntaxError:
error3 = messagebox.askokcancel("Value Error ", "Did u learn maths ?")
if error3 == True:
pass
else:
root.quit()
## Make our labels
def whatfunction_add():
global mylabel_add
mylabel_add = Label(root, text= add1 + " = " + e.get(), bg='black', fg="white")
mylabel_add.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_add_():
global mylabel_add
mylabel_add = Label(root, text= add2 + " = " + e_.get(), bg='black', fg="white")
mylabel_add.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_sub():
global mylabel_sub
mylabel_sub = Label(root, text= sub1 + " = " + e.get(), bg='black', fg="white")
mylabel_sub.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_sub_():
global mylabel_sub
mylabel_sub = Label(root, text= sub2 + " = " + e_.get(), bg='black', fg="white")
mylabel_sub.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_mult():
global mylabel_mult
mylabel_mult = Label(root, text= mult1 + " = " + e.get(), bg='black', fg="white")
mylabel_mult.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_mult_():
global mylabel_mult
mylabel_mult = Label(root, text= mult2 + " = " + e_.get(), bg='black', fg="white")
mylabel_mult.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_div():
global mylabel_div
mylabel_div = Label(root, text= div1 + " = " + e.get(), bg='black', fg="white")
mylabel_div.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_div_():
global mylabel_div
mylabel_div = Label(root, text= div2 + " = " + e_.get(), bg='black', fg="white")
mylabel_div.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def whatfunction_rem():
global mylabel_rem
mylabel_rem = Label(root, text= rem2 + " = " + e_.get(), bg='black', fg="white")
mylabel_rem.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_pow():
global mylabel_pow
mylabel_pow = Label(root, text= power_what + " = " + e_.get(), bg='black', fg="white")
mylabel_pow.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_sqr():
global mylabel_sqr
mylabel_sqr = Label(root, text= power_what + " = " + e_.get(), bg='black', fg="white")
mylabel_sqr.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_pi():
global mylabel_pi
mylabel_pi = Label(root, text= power_what + " = " + e_.get(), bg='black', fg="white")
mylabel_pi.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_sqrt():
global mylabel_sqrt
mylabel_sqrt = Label(root, text= power_what + " = " + e_.get(), bg='black', fg="white")
mylabel_sqrt.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
def whatfunction_fact():
global mylabel_fact
mylabel_fact = Label(root, text= power_what + " = " + e_.get(), bg='black', fg="white")
mylabel_fact.grid(row=2, column=0, columnspan=2, padx=40, pady=3)
# Define buttons
Button_1 = Button(tab1, text="1", padx=20, pady=15, bg='grey', command=lambda: button_click(1))
Button_2 = Button(tab1, text="2", padx=20, pady=15, command=lambda: button_click(2))
Button_3 = Button(tab1, text="3", padx=20, pady=15, command=lambda: button_click(3))
Button_4 = Button(tab1, text="4", padx=20, pady=15, command=lambda: button_click(4))
Button_5 = Button(tab1, text="5", padx=20, pady=15, command=lambda: button_click(5))
Button_6 = Button(tab1, text="6", padx=20, pady=15, command=lambda: button_click(6))
Button_7 = Button(tab1, text="7", padx=20, pady=15, command=lambda: button_click(7))
Button_8 = Button(tab1, text="8", padx=20, pady=15, command=lambda: button_click(8))
Button_9 = Button(tab1, text="9", padx=20, pady=15, command=lambda: button_click(9))
Button_0 = Button(tab1, text="0", padx=20, pady=15, command=lambda: button_click(0))
Button_add = Button(tab1, text="+", padx=17, pady=15, command=lambda: button_click(' + '))
Button_subtract = Button(tab1, text="-", padx=20, pady=15, command=lambda: button_click(' - '))
Button_multiply = Button(tab1, text="x", padx=18, pady=15, command=lambda: button_click(' * '))
Button_divide = Button(tab1, text="÷", padx=17, pady=15, command=lambda: button_click(' / '))
Button_undo = Button(tab1, text="⌫ ", padx=17, pady=15, command=undo_last)
Button_equal = Button(tab1, text="=", padx=18, pady=15, command=button_equal)
Button_clear = Button(tab1, text="clear", padx=8, pady=15, command=button_clear)
Button_point = Button(tab1, text=".", padx=22, pady=15, command=lambda: button_click('.'))
Button_open_paranthesis = Button(tab1, text="(", padx=20, pady=15, command=lambda: button_click('('))
Button_close_paranthesis = Button(tab1, text=")", padx=20, pady=15, command=lambda: button_click(')'))
Button_exit = Button(tab1, text="Exit", padx=8, pady=15, command=button_exit)
""""""""""""""""""""""""""""""""""""""""""
##def advanced():
Button_1_ = Button(tab2, text="1", padx=20, pady=15, command=lambda: button_click(1))
Button_2_ = Button(tab2, text="2", padx=20, pady=15, command=lambda: button_click(2))
Button_3_ = Button(tab2, text="3", padx=20, pady=15, command=lambda: button_click(3))
Button_4_ = Button(tab2, text="4", padx=20, pady=15, command=lambda: button_click(4))
Button_5_ = Button(tab2, text="5", padx=20, pady=15, command=lambda: button_click(5))
Button_6_ = Button(tab2, text="6", padx=20, pady=15, command=lambda: button_click(6))
Button_7_ = Button(tab2, text="7", padx=20, pady=15, command=lambda: button_click(7))
Button_8_ = Button(tab2, text="8", padx=20, pady=15, command=lambda: button_click(8))
Button_9_ = Button(tab2, text="9", padx=20, pady=15, command=lambda: button_click(9))
Button_0_ = Button(tab2, text="0", padx=20, pady=15, command=lambda: button_click(0))
Button_add_ = Button(tab2, text="+", padx=17, pady=15, command=lambda: button_click('+'))
Button_subtract_ = Button(tab2, text="-", padx=20, pady=15, command=lambda: button_click('-'))
Button_multiply_ = Button(tab2, text="x", padx=18, pady=15, command=lambda: button_click('*'))
Button_divide_ = Button(tab2, text="÷", padx=17, pady=15, command=lambda: button_click('/'))
Button_equal_ = Button(tab2, text="=", padx=20, pady=15, command=button_equal_)
Button_clear_ = Button(tab2, text="clear", padx=8, pady=15, command=button_clear_)
Button_point_ = Button(tab2, text=".", padx=22, pady=15, command=lambda: button_click_('.'))
Button_open_paranthesis_ = Button(tab2, text="(", padx=20, pady=15, command=lambda: button_click_('('))
Button_close_paranthesis_ = Button(tab2, text=")", padx=20, pady=15, command=lambda: button_click_(')'))
Button_remainder_ = Button(tab2, text="%", padx=20, pady=15, command=lambda: button_click('%'))
Button_power_ = Button(tab2, text="x^y", padx=12, pady=15, command=lambda: button_click('**'))