1+ # this is a Calculator made by Akagra
2+
3+ from tkinter import *
4+
5+ root = Tk ()
6+ root .title ("My First calculator Software by Akagra" )
7+ root .minsize (width = 364 , height = 523 )
8+ root .maxsize (width = 364 , height = 523 )
9+ #Code For Icon Has to pasted here
10+
11+ def ScitechzCalc (source , side ):
12+ storeObj = Frame (source , borderwidth = 4 , bd = 4 , bg = "cornsilk4" )
13+ storeObj .pack (side = side , expand = YES , fill = BOTH )
14+ return storeObj
15+
16+ def button (source , side , text , command = None ):
17+ storeObj = Button (source , bg = "cornsilk2" , fg = "gray5" , text = text , command = command )
18+ storeObj .pack (side = side , expand = YES , fill = BOTH )
19+ return storeObj
20+
21+ class app (Frame ):
22+ def __init__ (self ):
23+ Frame . __init__ (self )
24+ self .option_add ('*Font' , 'Helvetica 22 italic' , )
25+ self .pack (expand = YES , fill = BOTH )
26+
27+
28+ display = StringVar ()
29+ Entry (self , relief = RIDGE ,
30+ textvariable = display ,justify = 'right' ,bd = 26 ,fg = "white" ,bg = "cornsilk4" ).pack (side = TOP , expand = YES ,
31+ fill = BOTH )
32+
33+ for clearBut in (["CLEAR" ],):
34+ erase = ScitechzCalc (self , TOP )
35+ for ichar in clearBut :
36+ button (erase , LEFT , ichar ,
37+ lambda storeObj = display , q = ichar : storeObj .set ('' ))
38+
39+ for NumBut in ("789/" , "456*" , "123-" , "0.+" ):
40+ FunctionNum = ScitechzCalc (self , TOP )
41+ for char in NumBut :
42+ button (FunctionNum , LEFT , char ,
43+ lambda storeObj = display , q = char : storeObj .set (storeObj .get () + q ))
44+
45+ EqualsButton = ScitechzCalc (self , TOP )
46+ for iEquals in "=" :
47+ if iEquals == '=' :
48+ btniEquals = button (EqualsButton , LEFT , iEquals )
49+ btniEquals .bind ('<ButtonRelease-1>' ,
50+ lambda e , s = self , storeObj = display : s .calc (storeObj ), '+' )
51+ else :
52+ btniEquals = button (EqualsButton , LEFT , iEquals ,
53+ lambda storeObj = display , s = ' %s ' % iEquals : storeObj .set (storeObj .get ()+ s ))
54+
55+
56+ def calc (self , display ):
57+ try :
58+ display .set (eval (display .get ()))
59+ except :
60+ display .set ("::Error::" )
61+
62+ if __name__ == '__main__' :
63+ app ().mainloop ()
0 commit comments