Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- def but1():
- bt1 = entry2.get()
- display2.set (str(bt1) + "1")
- def but2():
- bt1 = entry2.get()
- display2.set (str(bt1) + "2")
- def but3():
- bt1 = entry2.get()
- display2.set (str(bt1) + "3")
- def but4():
- bt1 = entry2.get()
- display2.set (str(bt1) + "4")
- def but5():
- bt1 = entry2.get()
- display2.set (str(bt1) + "5")
- def but6():
- bt1 = entry2.get()
- display2.set (str(bt1) + "6")
- def but7():
- bt1 = entry2.get()
- display2.set (str(bt1) + "7")
- def but8():
- bt1 = entry2.get()
- display2.set (str(bt1) + "8")
- def but9():
- bt1 = entry2.get()
- display2.set (str(bt1) + "9")
- def but0():
- bt1 = entry2.get()
- display2.set (str(bt1) + "0")
- def but11():
- bt1 = entry2.get()
- display2.set (str(bt1) + " + ")
- def but12():
- bt1 = entry2.get()
- display2.set (str(bt1) + " - ")
- def but13():
- bt1 = entry2.get()
- display2.set (str(bt1) + " * ")
- def but14():
- bt1 = entry2.get()
- display2.set (str(bt1) + " / ")
- def but15():
- bt1 = entry2.get()
- display2.set (str(bt1) + " . ")
- def but16():
- bt1 = entry2.get()
- display2.set (str(bt1) + "-")
- def operation():
- eq1 = str(entry2.get())
- a, op, b = eq1.split()
- if op == "+":
- display2.set(float(a) + float(b))
- elif op =="-":
- display2.set (float(a) - float(b))
- elif op =="*":
- display2.set (float(a) * float(b))
- elif op =="/":
- display2.set (float(a) / float(b))
- def clear():
- display2.set("")
- # main
- root = Tk()
- root.title("Calculator by Ash")
- root.geometry("320x670")
- gap1= Frame(root, height=20, width=50)
- gap1.pack()
- global display2
- display2 = StringVar(None)
- entry2 = Entry(root, justify = 'center', textvariable=display2, width=30)
- entry2.pack()
- gap2= Frame(root, height=20, width=50)
- gap2.pack()
- app = Frame(root)
- app.grid()
- frame1= Frame(root, width=20)
- frame1.pack()
- button1 = Button(frame1, text = "1", height=7, width=7, command=but1)
- button1.pack(side = LEFT )
- button2 = Button(frame1, text = "2", height=7, width=7, command=but2)
- button2.pack( side = LEFT )
- button3 = Button(frame1, text = "3", height=7, width=7, command=but3)
- button3.pack( side = LEFT )
- button4 = Button(frame1, text = "*", height=7, width=7, command=but13)
- button4.pack( side = LEFT )
- frame2= Frame(root, width=20)
- frame2.pack()
- button5 = Button(frame2, text = "4", height=7, width=7, command=but4)
- button5.pack(side = LEFT )
- button6 = Button(frame2, text = "5", height=7, width=7, command=but5)
- button6.pack( side = LEFT )
- button7 = Button(frame2, text = "6", height=7, width=7, command=but6)
- button7.pack( side = LEFT )
- button8 = Button(frame2, text = "+", height=7, width=7, command=but11)
- button8.pack( side = LEFT )
- frame3= Frame(root, width=20)
- frame3.pack()
- button9 = Button(frame3, text = "7", height=7, width=7, command=but7)
- button9.pack(side = LEFT )
- button10 = Button(frame3, text = "8", height=7, width=7, command=but8)
- button10.pack( side = LEFT )
- button11 = Button(frame3, text = "9", height=7, width=7, command=but9)
- button11.pack( side = LEFT )
- button12 = Button(frame3, text = "-", height=7, width=7, command=but12)
- button12.pack(side = LEFT )
- frame4= Frame(root, width=20)
- frame4.pack()
- button13 = Button(frame4, text = "0", height=7, width=7, command=but0)
- button13.pack(side = LEFT )
- button14 = Button(frame4, text = "(C)", height=7, width=7,command=clear)
- button14.pack(side = LEFT )
- button15 = Button(frame4, text = "(.)", height=7, width=7, command=but15)
- button15.pack( side = LEFT )
- button16 = Button(frame4, text = "/", height=7, width=7, command=but14)
- button16.pack( side = LEFT )
- frame5= Frame(root, width=20)
- frame5.pack()
- button17 = Button(frame5, text = "=", height=7, width=7, command=operation)
- button17.pack( side = LEFT )
- button18 = Button(frame5, text = "(-)", height=7, width=7, command=but16)
- button18.pack( side = LEFT )
- #label = Label(app, text = "rawr")
- #label.grid()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement