-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleCalculator.py
125 lines (109 loc) · 3.63 KB
/
SimpleCalculator.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
119
120
121
122
123
124
125
#SimpleCalculater
#Developed and Designed by Jaspreet Singh
#import libraries
from tkinter import *
#global representation
button1 = []
button2 = []
i = 0
for i in range(8, -1, -1):
button1.append(i)
for i in range(5,-1,-1):
button2.append(i)
print(i)
#FUNCTION HERE
#Calculation here
#You can add more function division and multiplication here
def data(event):
value = event.widget.cget("text")
if (value == "="):
if ("+" in Data.get()):
v = Data.get().split("+")
Data.set(int(v[0]) + int(v[1]))
print(v)
if ("-" in Data.get()):
v = Data.get().split("-")
Data.set(int(v[0]) - int(v[1]))
print(v)
if (value != "=" and value != "C"):
Data.set(Data.get() + value)
editText.update()
if (value == "C"):
Data.set(int(int(Data.get()) / 10))
editText.update()
#Theme Changing you can change your or add your custom theme here
#For Custom Change just change bg or fg with your colur combination
def change():
global i
i = i + 1
if (i % 2 == 0):
Cvalue.set("LightMode")
root.config(bg="black")
button2[5].update()
for k in range(8, -1, -1):
button1[k].config(bg="black", fg="white")
for k in range(5,-1,-1):
button2[k].config(bg="black", fg="white")
editText.config(bg="black", fg="white")
else:
Cvalue.set("Darkmode")
button2[5].update()
root.config(bg="white")
editText.config(bg="white", fg="black")
for k in range(8, -1, -1):
button1[k].config(bg="white", fg="black")
for k in range(5,-1,-1):
button2[k].config(bg="white", fg="black")
editText.config(bg="white", fg="black")
#Main Function(Entry point of first execution)
root = Tk()
Cvalue = StringVar()
Cvalue.set("DarkMode")
button2[5] = Button(root, textvariable=Cvalue, command=change)
button2[5].pack(anchor=W)
root.geometry("500x700")
root.title("Developed by JASPREET SINGH")
root.maxsize(500, 700)
root.minsize(500, 700)
Data = StringVar()
Data.set("")
editText = Entry(root, font="lucida 60 bold", textvariable=Data)
editText.pack(fill=X, ipady=8, pady=40)
frame = Frame(root)
for i in range(9, 6, -1):
button1[9 - i] = Button(frame, text=f"{i}", font="lucida 30 bold", pady=8, padx=52)
button1[9 - i].pack(side=LEFT)
button1[9 - i].bind('<Button-1>', data)
frame.pack()
frame = Frame(root)
for i in range(6, 3, -1):
button1[9 - i] = Button(frame, text=f"{i}", font="lucida 30 bold", pady=8, padx=52)
button1[9 - i].pack(side=LEFT)
button1[9 - i].bind('<Button-1>', data)
frame.pack()
frame = Frame(root)
for i in range(3, 0, -1):
button1[9 - i] = Button(frame, text=f"{i}", font="lucida 30 bold", pady=8, padx=52)
button1[9 - i].pack(side=LEFT)
button1[9 - i].bind('<Button-1>', data)
frame.pack()
frame = Frame(root)
button2[0] = Button(frame, text="0", font="lucida 30 bold", pady=8, padx=52)
button2[0].pack(side=LEFT)
button2[0].bind('<Button-1>', data)
button2[1] = Button(frame, text="-", font="lucida 30 bold", pady=8, padx=52)
button2[1].pack(side=LEFT)
button2[1].bind('<Button-1>', data)
button2[2] = Button(frame, text="+", font="lucida 30 bold", pady=8, padx=52)
button2[2].pack(side=LEFT)
button2[2].bind('<Button-1>', data)
frame.pack()
frame = Frame(root)
button2[3] = Button(frame, text="=", font="lucida 30 bold", pady=8, padx=52)
button2[3].pack(side=RIGHT)
button2[3].bind('<Button-1>', data)
button2[4] = Button(frame, text="C", font="lucida 30 bold", pady=8, padx=52)
button2[4].pack(side=RIGHT)
button2[4].bind('<Button-1>', data)
frame.pack()
root.mainloop()