Python Forum
Adding a sqrt function syntax error and <build-in function sqrt> from tkinter import
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding a sqrt function syntax error and <build-in function sqrt> from tkinter import
#1
# 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
 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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  rotate error function schniefen 0 867 Dec-07-2022, 02:40 PM
Last Post: schniefen
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,255 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  Manually raising two error types with a function that computes sqfeet to sqmeters sean1 7 2,071 Nov-12-2021, 05:01 PM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 1,968 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 1,963 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 1,928 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,485 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Invalid syntax error, where? tucktuck9 2 3,378 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 3,065 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 3,994 Jan-25-2020, 03:40 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020