from tkinter import*class Calculator:
def__init__(self,master):
self.master = master
master.title("My Calculator @ www.pickupbrain.com")
master.configure(bg='#C0C0C0')
#creating screen widgetself.screen =Text(master, state='disabled', width=50,height=3, background="#EAFAF1", foreground="#000000",font=("Arial",15,"bold"))
#Screen position in windowself.screen.grid(row=0,column=0,columnspan=4,padx=2,pady=2)
self.screen.configure(state='normal')
#initialize screen value as emptyself.equation=''#create buttons
b1 =self.createButton(7)
b2 =self.createButton(8)
b3 =self.createButton(9)
b4 =self.createButton(u"u232B",None)
b5 =self.createButton(4)
b6 =self.createButton(5)
b7 =self.createButton(6)
b8 =self.createButton(u"u00F7")
b9 =self.createButton(1)
b10 =self.createButton(2)
b11 =self.createButton(3)
b12 =self.createButton('*')
b13 =self.createButton('.')
b14 =self.createButton(0)
b15 =self.createButton('+')
b16 =self.createButton('-')
b17 =self.createButton('=', None,35)
#stored all buttons in list
buttons = [b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17]
#initalize counter
count=0#arrange buttons with grid managerfor row in range(1,5):
for column in range(4):
buttons[count].grid(row = row, column= column,padx=0,pady=0)
count +=1#arrange last button '=' at the bottom
buttons[16].grid(row=5,column=0,columnspan=4)
defcreateButton(self,val,write=True,width=8):
#this function creates a button and takes one compulsary argument, the value that should be on the buttonreturnButton(self.master,text=val,command= lambda:self.click(val,write),width=width,background="#ffffff",foreground ="#1f4bff",font=("times",20,"bold"))
defclick(self,text,write):
#this function handles the actions when you#click a button 'write' arguement, if true#than value val should be written on screen,#if none then should not be written on screenif write == None:
#Evaluates when there is an equation to be evaluatedif text =='='andself.equation:
#replace the unicode values of division ./. with python division#symbol / using regexself.equation = re.sub(u"u00F7", '/', self.equation)
print(self.equation)
answer =str(eval(self.equation))
self.clear_screen()
self.insert_screen(answer,newline =True)
elif text == u"u232B":
self.clear_screen()
else:
#add text to screenself.insert_screen(text)
defclear_screen(self):
#to clear screen#set equation to empty before deleteing screenself.equation =''self.screen.configure(state ='normal')
self.screen.delete('1.0', END)
definsert_screen(self, value, newline =False):
self.screen.configure(state ='normal')
self.screen.insert(END,value)
#record every value inserted in screenself.equation +=str(value)
self.screen.configure(state ='disabled')
defcalci():
#Function that creates calculator GUI
root =Tk()
my_gui =Calculator(root)
root.mainloop()
# Running Calculator calci()
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email