how to create calculator app using python

Namaste Friends,



                                Today's Tutorial is about how to create a calculator using python language.
because to be an expert, we need to start from beginners level. so, I think this tutorial is very important for beginners and for newbies also.



here, 

     for this tutorial, we will use python Tkinter Module For Calculator GUI Because Tkinter is very easy to use. 


so' let's start.



here, I am showing my demo python codes.


 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
#!/usr/bin/python
# This Example is Written By
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.in/

    Note: We Feel Proud To Be Indian
######################################################
'''

from Tkinter import *

def icalc(source, side):
 storeobj=Frame(source, borderwidth=4, bd=4, bg="powder blue")
 storeobj.pack(side=side, expand=YES, fill=BOTH)
 return storeobj

def button(source, side, text, command=None):
 storeobj=Button(source, text=text, command=command)
 storeobj.pack(side=side, expand=YES, fill=BOTH)
 return storeobj

class app(Frame):
 def __init__(self):

  Frame.__init__(self)
  self.option_add('*Font','arial 20 bold')
  self.pack(expand=YES, fill=BOTH)
  self.master.title('calculator')
  display=StringVar()
  def calcu():
   data=display.get()
   if '.' not in data:
    data1=data.replace('+', '.0+')
    data2=data1.replace('-', '.0-')
    data3=data2.replace('*', '.0*')
    data4=data3.replace('/', '.0/')
    try:
     display.set(eval(data4))
    except:
     display.set('No Input Value')
   else:
    display.set(eval(data))
  Entry(self, relief=SUNKEN, textvariable=display, bd=10,justify='right',bg='powder blue', width=30).pack(side=TOP, expand=YES, fill=BOTH)
  for clearbut in (['CE'],['C']):
   erase=icalc(self, TOP)
   for ichar in clearbut:
    button(erase, LEFT, ichar, lambda storeobj=display, q=ichar: storeobj.set(''))
  for numbut in ("789/","456*","123-","0.+"):
   functionnum=icalc(self, TOP)
   for char in numbut:
    button(functionnum, LEFT, char, lambda storeobj=display, q=char: storeobj.set(storeobj.get()+q))
  equalbutton=icalc(self, TOP)
  btequal=button(equalbutton, LEFT, '=', calcu)
if __name__=='__main__':
 app().mainloop()


and if you want to see how this script works then check below video. 




In this video you will learn about How to Create Calculator Using python language


created By
S.S.B
surajsinghbisht054@gmail.com

Thanks For Support
Please, 
Feel Free To Leave A Comment 
If Our Article has Helped You.



Share this

Related Posts

Previous
Next Post »