# so this is the calculator that I copied code from youtube and try to add a new function but it keeps getting errors like syntax error: invalid syntax and <build-in function sqrt>
This is the line of the code that I want to add a sqrt function. I know there something wrong with it
little advice from you guys I really appreciate. Sorry for my bad english
This is the line of the code that I want to add a sqrt function. I know there something wrong with it
little advice from you guys I really appreciate. Sorry for my bad english
def equlbut(): global operator sqrt=str(eval(operator)) textin.set(sqrt()) operator=''
from tkinter import * from math import * me=Tk() me.geometry("500x500") me.title("CALCU") melabel = Label(me,text="CaLcU",bg='Grey',font=("Consolas",30,'bold')) melabel.pack(side=TOP) me.config(background='Orange') textin=StringVar() operator="" def clickbut(number): #lambda:clickbut(1) global operator operator=operator+str(number) textin.set(operator) def equlbut(): global operator add=str(eval(operator)) textin.set(add) operator='' def equlbut(): global operator sub=str(eval(operator)) textin.set(sub) operator='' def equlbut(): global operator mul=str(eval(operator)) textin.set(mul) operator='' def equlbut(): global operator div=str(eval(operator)) textin.set(div) operator='' def equlbut(): global operator sqrt=str(eval(operator)) textin.set(sqrt()) operator='' def clrbut(): textin.set('') but1=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(7),text="7",font=("Courier New",16,'bold')) but1.place(x=110,y=190) but2=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(4),text="4",font=("Courier New",16,'bold')) but2.place(x=110,y=260) but3=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(1),text="1",font=("Courier New",16,'bold')) but3.place(x=110,y=330) but4=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(8),text="8",font=("Courier New",16,'bold')) but4.place(x=200,y=190) but5=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(5),text="5",font=("Courier New",16,'bold')) but5.place(x=200,y=260) but6=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(2),text="2",font=("Courier New",16,'bold')) but6.place(x=200,y=330) but7=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(9),text="9",font=("Courier New",16,'bold')) but7.place(x=290,y=190) but8=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(6),text="6",font=("Courier New",16,'bold')) but8.place(x=290,y=260) but9=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(3),text="3",font=("Courier New",16,'bold')) but9.place(x=290,y=330) but0=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(0),text="0",font=("Courier New",16,'bold')) but0.place(x=110,y=400) butdot=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut("."),text=".",font=("Courier New",16,'bold')) butdot.place(x=200,y=400) butpl=Button(me,padx=14,pady=48,bd=4,bg='white',text="+",command=lambda:clickbut("+"),font=("Courier New",16,'bold')) butpl.place(x=380,y=330) butsub=Button(me,padx=14,pady=14,bd=4,bg='white',text="-",command=lambda:clickbut("-"),font=("Courier New",16,'bold')) butsub.place(x=380,y=260) butml=Button(me,padx=14,pady=14,bd=4,bg='white',text="x",command=lambda:clickbut("*"),font=("Courier New",16,'bold')) butml.place(x=380,y=190) butdiv=Button(me,padx=14,pady=14,bd=4,bg='white',text="÷",command=lambda:clickbut("/"),font=("Courier New",16,'bold')) butdiv.place(x=380,y=140) butper=Button(me,padx=16,pady=16,bd=6,bg='white',text="%",command=lambda:clickbut("%"),font=("Courier New",12,'bold')) butper.place(x=20,y=190) butmu=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(MU),text="MU",font=("Courier New",13,'bold')) butmu.place(x=20,y=140) butmrc=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(MU),text="MRC",font=("Courier New",9,'bold')) butmrc.place(x=110,y=140) butmpl=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(MU),text="M+",font=("Courier New",11,'bold')) butmpl.place(x=200,y=140) butminu=Button(me,padx=14,pady=14,bd=4,bg='white',command=lambda:clickbut(MU),text="M-",font=("Courier New",11,'bold')) butminu.place(x=290,y=140) butsqrt=Button(me,padx=12,pady=12,bd=3,bg='white',command=lambda:clickbut(sqrt),text="√",font=("Courier New",16,'bold')) butsqrt.place(x=20,y=260) butclear=Button(me,padx=14,pady=14,bd=4,bg='white',text="CE",command=clrbut,font=("Courier New",12,'bold')) butclear.place(x=20,y=400) buton=Button(me,padx=14,pady=14,bd=4,bg='white',text="ON",command=clrbut,font=("Courier New",12,'bold')) buton.place(x=20,y=330) butequal=Button(me,padx=14,pady=14,bd=4,bg='white',command=equlbut,text="=",font=("Courier New",16,'bold')) butequal.place(x=290,y=400) metext=Entry(me,font=("Courier New",12,'bold'),textvar=textin,width=30,bd=30,bg='gray') metext.pack() me.mainloop()