Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from tkinter import *
- root = Tk()
- frame = Frame(root)
- frame.pack()
- def clear():
- global operator
- operator=""
- text_Input.set("")
- def buttonClick(numbers):
- global operator
- operator= operator+str(numbers)
- text_Input.set(operator)
- def buttonEqual():
- global operator
- equal=str(eval(operator))
- text_Input.set(equal)
- operator=""
- operator=""
- root.title("Calculator")
- text_Input =StringVar()
- #DISPLAY
- def display():
- topframe = Frame(root)
- topframe.pack(side = TOP)
- txtDisplay=Entry(frame, textvariable= text_Input, bd= 50, insertwidth= 0, font= 40)
- txtDisplay.pack(side= TOP)
- #BOTTOM ROW OF NUMBERS AND FUNCTIONS
- def bot_row():
- frame4 = Frame(root)
- frame4.pack(side = TOP)
- buttonzero= Button(frame4, padx= 44, pady= 15, bd=8, text= "0", fg="green",bg="red", command= lambda:buttonClick(0))
- buttonzero.pack(side =LEFT)
- buttonsubtract= Button(frame4, padx= 15, pady= 15, bd=8, text= "-", fg="green",bg="red", command= lambda:buttonClick("-"))
- buttonsubtract.pack(side =LEFT)
- buttonaddition= Button(frame4, padx= 13, pady= 15, bd=8, text= "+", fg="green",bg="red", command= lambda:buttonClick("+"))
- buttonaddition.pack(side =LEFT)
- buttonequal= Button(frame4, padx= 14, pady= 15, bd=8, text= "=", fg="green",bg="red", command= lambda:buttonEqual())
- buttonequal.pack(side =LEFT
- )
- #BOTTWO ROW OF NUMBERS AND FUNCTIONS
- def bottwo_row():
- frame3 = Frame(root)
- frame3.pack(side = TOP)
- buttonone= Button(frame3,padx= 15, pady= 15, bd=8, text= "1", fg="green", bg="red", command= lambda:buttonClick(1))
- buttonone.pack(side =LEFT)
- buttontwo= Button(frame3,padx= 15, pady= 15, bd=8, text= "2", fg="green", bg="red", command= lambda:buttonClick(2))
- buttontwo.pack(side =LEFT)
- buttonthree= Button(frame3,padx= 15, pady= 15, bd=8, text= "3", fg="green", bg="red", command= lambda:buttonClick(3))
- buttonthree.pack(side =LEFT)
- buttonclosebracket= Button(frame3,padx= 15, pady= 15, bd=8, text= ")", fg="green", bg="red", command= lambda:buttonClick(")"))
- buttonclosebracket.pack(side =LEFT)
- buttondivision= Button(frame3, padx= 15, pady= 15, bd=8, text= "/", fg="green", bg="red", command= lambda:buttonClick("/"))
- buttondivision.pack(side =LEFT)
- #BOTTHREE ROW OF NUMBERS AND FUNCTIONS
- def botthree_row():
- frame2 = Frame(root)
- frame2.pack(side = TOP)
- buttonfour= Button(frame2,padx= 15, pady= 15, bd=8, text= "4", fg="green", bg="red", command= lambda:buttonClick(4))
- buttonfour.pack(side =LEFT)
- buttonfive= Button(frame2,padx= 15, pady= 15, bd=8, text= "5", fg="green", bg="red", command= lambda:buttonClick(5))
- buttonfive.pack(side =LEFT)
- buttonsix= Button(frame2,padx= 15, pady= 15, bd=8, text= "6", fg="green", bg="red", command= lambda:buttonClick(6))
- buttonsix.pack(side =LEFT)
- buttonopenbracket= Button(frame2, padx= 15,pady= 15, bd=8, text= "(", fg="green", bg="red", command= lambda:buttonClick("("))
- buttonopenbracket.pack(side =LEFT)
- buttonmultiply= Button(frame2, padx= 15, pady= 15, bd=8, text= "*", fg="green", bg="red", command= lambda:buttonClick("*"))
- buttonmultiply.pack(side =LEFT)
- #BOTFOUR OF NUMBERS AND FUNCTIONS
- def botfour_row():
- frame1 = Frame(root)
- frame1.pack(side = TOP)
- buttonseven= Button(frame1,padx= 15, pady= 15, bd=8, text= "7", fg="green", bg="red", command= lambda:buttonClick(7))
- buttonseven.pack(side =LEFT)
- buttoneight= Button(frame1,padx= 15, pady= 15, bd=8, text= "8", fg="green", bg="red", command= lambda:buttonClick(8))
- buttoneight.pack(side =LEFT)
- buttonnine= Button(frame1,padx= 15, pady= 15, bd=8, text="9", fg= "green", bg="red", command= lambda:buttonClick(9))
- buttonnine.pack(side =LEFT)
- buttonclear= Button(frame1,padx=35, pady= 15, bd=8, text= "CLR", fg="green", bg="red2", command= lambda:clear())
- buttonclear.pack(side =LEFT)
- display()
- bot_row()
- bottwo_row()
- botthree_row()
- botfour_row()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement