# How to Create Calculator Using python And Tkinter

Namaste friends,

Today, I gonna to show you how we can simply create a calculator using python and Tkinter language.

here, below i have already given source code of my script.

In This Script I tried my best to Create this script more easy for learning and reading..

 ``` 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``` ```import Tkinter # Functions For Doing Functions Automatically & Easily def iframe(parent): store=Tkinter.Frame(parent) store.pack(fill='both', expand="yes") return store # Calculation Engine def dialnum(text): if text=="C": if len(displayvar.get())!=0: value=displayvar.get() displayvar.set(value[:-1]) elif text=="CE": displayvar.set('') elif text=="=": k=displayvar.get() try: displayvar.set(eval(k)) except: displayvar.set('Error') else: displayvar.set(displayvar.get()+text) return def ibutton(parent,text): store=Tkinter.Button(parent, text=text,bg="powder blue",relief="raised", font=('arial 15 bold'),\ width=10,height=2) store.pack(side='left',fill='both', expand="yes") store['command']=lambda: dialnum(store['text']) return store # Here Creating Parent window root=Tkinter.Tk(className=" Calculator") # Here String Variable displayvar=Tkinter.StringVar() # Creating Display displaywidget=Tkinter.Entry(iframe(root), font=('arial 55 bold'),fg="blue",\ justify="right", relief="sunken",bd=15, textvariable=displayvar ) displaywidget.pack(fill='both', expand="yes", side="top") # Creating Buttons button_data=[ (['C']), (['CE']), ('7','8','9','(',')'), ('4','5','6','*','**'), ('1','2','3','/','%'), ('.','0','=','+','-')] # Creating Dialing Pad keypad=iframe(root) for i in button_data: print i storeframe=iframe(keypad) storeframe.pack(fill='both', expand="yes", side="top") for j in i: ibutton(storeframe,j) # Creating Operater Pad keypad_1=iframe(root) # Parent Windows Mainloop root.mainloop()```

Done!

For More Tips and Tricks