from tkinter import * import random #for random colour backgrounds col=['pink','cyan','blue','navy','red','yellow','orange','grey','black','white','green','gold'] r=Tk() r.geometry('400x500') r.title('DOUBLE CALCULATOR By HARSHA') #button function def bu(tex,cc,xx,yy): Button(r,text=tex,bg='orange',fg='black',bd=7,command=cc).place(x=int(xx),y=int(yy),width=40,height=40) #main part of calculator def cal(): Frame(r,width=1200,height=2000,bg=random.choice(col)).place(x=0,y=0) Frame(r,width=290,height=300,bg=random.choice(col)).place(x=50,y=135) Frame(r,width=200,height=22,bg='pink').place(x=95,y=93) e1=Entry(r,bg='yellow') e1.place(x=50,y=10,height=25,width=290) e2=Entry(r,bg='yellow') e2.place(x=50,y=50,height=25,width=290) def o(): O['text']='Enter valid number' def os(): O['text']='Enter valid numbers' def sum(): try: O['text']=float(e1.get())+float(e2.get()) except: os() bu('+',sum,'70','160') def sub(): try: O['text']=float(e1.get())-float(e2.get()) except: os() bu('-',sub,'140','160') def mul(): try: O['text']=float(e1.get())*float(e2.get()) except: os() bu('*',mul,'210','160') def div(): try: O['text']=float(e1.get())/float(e2.get()) except: os() bu('/',div,'280','160') def sq(): try: O['text']=float(e1.get())**2 except: o() bu('x²',sq,'70','230') def sqrt(): try: O['text']=float(e1.get())**0.5 except: o() bu('√',sqrt,'140','230') def pow(): try: O['text']=float(e1.get())**float(e2.get()) except: os() bu('x^a',pow,'210','230') def powrt(): try: O['text']=float(e1.get())**(1/float(e2.get())) except: os() bu('x√',powrt,'280','230') def dice(): O['text']=random.randint(1,6) bu('DICE',dice,'70','300') def toss(): qq=random.randint(1,2) if qq==1: O['text']='HEADS' elif qq==2: O['text']='TAILS' bu('TOSS',toss,'140','300') def rand(): try: O['text']=random.randint(int(e1.get()),int(e2.get())) except: O['text']='enter valid numbers (num1