-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcApp.py
130 lines (91 loc) · 5.13 KB
/
CalcApp.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
126
127
128
129
130
from tkinter import *
from tkinter.ttk import *
import tkinter as tk
import pyautogui as pag
import datetime
class CalculatorAPP:
def __init__(self):
self.CalcWind = Tk()
self.CalcWind.geometry("460x510+800+100")
self.CalcWind.title("PS Calculator")
self.CalcWind.resizable(0, 0)
self.CalcWind.iconbitmap('logo.ico')
self.calcVal = tk.StringVar()
self.calcTmpVal = ''
self.outputEntry = Entry(self.CalcWind, width=50, justify="right", font=("Arial", 20), textvariable=self.calcVal)
self.outputEntry.pack(ipady=10)
self.FrameOne = tk.Frame(self.CalcWind)
self.FrameOne.pack(ipady=10)
self.btnOne = Button(self.FrameOne, text='(', width=8, command=lambda:self.showVal('('))
self.btnOne.pack(side="left", padx=10, ipady=10)
self.btnTwo = Button(self.FrameOne, text=')', width=8, command=lambda:self.showVal(')'))
self.btnTwo.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameOne, text='%', width=8, command=lambda:self.showVal('%'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameOne, text='AC', width=20, command=self.clearVal)
self.btnThree.pack(side="left", padx=10, ipady=10)
self.FrameTwo = tk.Frame(self.CalcWind)
self.FrameTwo.pack(ipady=10)
self.btnOne = Button(self.FrameTwo, text='9', width=8, command=lambda:self.showVal('9'))
self.btnOne.pack(side="left", padx=10, ipady=10)
self.btnTwo = Button(self.FrameTwo, text='8', width=8, command=lambda:self.showVal('8'))
self.btnTwo.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameTwo, text='7', width=8, command=lambda:self.showVal('7'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameTwo, text='+', width=20, command=lambda:self.showVal('+'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.FrameThree = tk.Frame(self.CalcWind)
self.FrameThree.pack(ipady=10)
self.btnOne = Button(self.FrameThree, text='6', width=8, command=lambda:self.showVal('6'))
self.btnOne.pack(side="left", padx=10, ipady=10)
self.btnTwo = Button(self.FrameThree, text='5', width=8, command=lambda:self.showVal('5'))
self.btnTwo.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameThree, text='4', width=8, command=lambda:self.showVal('4'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameThree, text='-', width=20, command=lambda:self.showVal('-'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.FrameFour = tk.Frame(self.CalcWind)
self.FrameFour.pack(ipady=10)
self.btnOne = Button(self.FrameFour, text='3', width=8, command=lambda:self.showVal('3'))
self.btnOne.pack(side="left", padx=10, ipady=10)
self.btnTwo = Button(self.FrameFour, text='2', width=8, command=lambda:self.showVal('2'))
self.btnTwo.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameFour, text='1', width=8, command=lambda:self.showVal('1'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameFour, text='/', width=20, command=lambda:self.showVal('/'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.FrameFive = tk.Frame(self.CalcWind)
self.FrameFive.pack(ipady=10)
self.btnOne = Button(self.FrameFive, text='0', width=8, command=lambda:self.showVal('0'))
self.btnOne.pack(side="left", padx=10, ipady=10)
self.btnTwo = Button(self.FrameFive, text='.', width=8, command=lambda:self.showVal('.'))
self.btnTwo.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameFive, text='*', width=8, command=lambda:self.showVal('*'))
self.btnThree.pack(side="left", padx=10, ipady=10)
self.btnThree = Button(self.FrameFive, text='=', width=20, command=self.getCalcVal)
self.btnThree.pack(side="left", padx=10, ipady=10)
chkCurrentYear = datetime.datetime.now().strftime("%Y")
if int(chkCurrentYear) > 2023:
cpyrightYear = "2023 - "+str(chkCurrentYear)
else:
cpyrightYear = "2023"
self.authorLabel = Label(self.CalcWind, text='PS Thamizhan - © '+str(cpyrightYear)+'. V1.0', font=("Segoe UI", 7))
self.authorLabel.pack(side=BOTTOM, ipady=20)
def showVal(self, txtVal):
self.calcTmpVal += txtVal
self.calcVal.set(self.calcTmpVal)
def clearVal(self):
self.calcTmpVal = ''
self.calcVal.set(self.calcTmpVal)
def getCalcVal(self):
try:
if (len(self.calcTmpVal) > 0):
res = eval(self.calcTmpVal)
self.calcVal.set(res)
except:
self.calcTmpVal = ''
self.calcVal.set('Error')
def runModule(self):
self.CalcWind.mainloop()
mod = CalculatorAPP()
mod.runModule()