def but_pnt_click():
inp_entry.insert(END, ".")
def but_0_click():
inp_entry.insert(END, "0")
def but_1_click():
inp_entry.insert(END, "1")
def but_2_click():
inp_entry.insert(END, "2")
def but_3_click():
inp_entry.insert(END, "3")
def but_4_click():
inp_entry.insert(END, "4")
def but_5_click():
inp_entry.insert(END, "5")
def but_6_click():
inp_entry.insert(END, "6")
def but_7_click():
inp_entry.insert(END, "7")
def but_8_click():
inp_entry.insert(END, "8")
def but_9_click():
inp_entry.insert(END, "9")
def but_kor_click():
global a,b
a=float(inp_entry.get())
if a>=0:
b="sqrt(a)"
inp_entry.delete(0, END)
else:
inp_entry.delete(0, END)
inp_entry.insert(END, "Error")
def but_mod_click():
global a,b
a=float(inp_entry.get())
b="abs(a)"
inp_entry.delete(0, END)
def but_d_click():
global a,b
a=float(inp_entry.get())
b="+"
inp_entry.delete(0, END)
def but_m_click():
global a,b
a=float(inp_entry.get())
b="-"
inp_entry.delete(0, END)
def Equal_click():
c=float(inp_entry.get())
if b=="+":
inp_entry.delete(0, END)
inp_entry.insert(END, a+c)
if b=="-":
inp_entry.delete(0, END)
inp_entry.insert(END, a-c)
if b=="*":
inp_entry.delete(0, END)
inp_entry.insert(END, a*c)
if b=="/":
if c!=0:
inp_entry.delete(0, END)
inp_entry.insert(END, a/c)
else:
inp_entry.delete(0, END)
inp_entry.insert(END, "Cannot divide by 0")
if b=="sqrt(a)":
inp_entry.delete(0, END)
inp_entry.insert(END, sqrt(a))
if b=="abs(a)":
inp_entry.delete(0, END)
inp_entry.insert(END, abs(a))
def but_p_click():
global a,b
a=float(inp_entry.get())
b="*"
inp_entry.delete(0, END)
def but_min_click():
global a,b
a=float(inp_entry.get())
b="/"
inp_entry.delete(0, END)
def bc_click():
inp_entry.delete(0, END)
from tkinter import *
from math import *
root = Tk()
root.title("Калькулятор")
root.geometry("400x400")
inp_entry = Entry(root)
inp_entry.place(x=10, y=20, width=380)
bc = Button(text="C", font="16", command=bc_click)
bc.place(x=10, y=60, width=40, height=40)
but_kor = Button(text="√", font="16", command=but_kor_click)
but_kor.place(x=115, y=60, width=40, height=40)
but_mod = Button(text="|x|", font="16", command=but_mod_click)
but_mod.place(x=220, y=60, width=40, height=40)
Equal = Button(text="=", font="16", command=Equal_click)
Equal.place(x=350, y=60, width=40, height=40)
but_0 = Button(text="0", font="16", command=but_0_click)
but_0.place(x=10, y=350, width=100, height=40)
but_pnt = Button(text=".", font="16", command=but_pnt_click)
but_pnt.place(x=190, y=350, width=40, height=40)
but_1 = Button(text="1", font="16", command=but_1_click)
but_1.place(x=10, y=300, width=40, height=40)
but_2 = Button(text="2", font="16", command=but_2_click)
but_2.place(x=100, y=300, width=40, height=40)
but_3 = Button(text="3", font="16", command=but_3_click)
but_3.place(x=190, y=300, width=40, height=40)
but_4 = Button(text="4", font="16", command=but_4_click)
but_4.place(x=10, y=250, width=40, height=40)
but_5 = Button(text="5", font="16", command=but_5_click)
but_5.place(x=100, y=250, width=40, height=40)
but_6 = Button(text="6", font="16", command=but_6_click)
but_6.place(x=190, y=250, width=40, height=40)
but_7 = Button(text="7", font="16", command=but_7_click)
but_7.place(x=10, y=200, width=40, height=40)
but_8 = Button(text="8", font="16", command=but_8_click)
but_8.place(x=100, y=200, width=40, height=40)
but_9 = Button(text="9", font="16", command=but_9_click)
but_9.place(x=190, y=200, width=40, height=40)
but_d = Button(text="+", font="16", command=but_d_click)
but_d.place(x=290, y=350, width=40, height=40)
but_m = Button(text="-", font="16", command=but_m_click)
but_m.place(x=290, y=300, width=40, height=40)
but_p = Button(text="*", font="16", command=but_p_click)
but_p.place(x=290, y=250, width=40, height=40)
but_min = Button(text="/", font="16", command=but_min_click)
but_min.place(x=290, y=200, width=40, height=40)
b = ["+", "-", "*", "/", "sqrt(a)", "abs(a)"]
root.mainloop()
Иногда работает, иногда нет. В основном пишет, что b is not defined (строка 36) и could not convert string to float (строка 46)