написал простой калькулятор, но есть проблема. При нажатии кнопки "OP" и "=" (Последнее только при ошибке в расчётах) то клавиша просто залипает в нажатом состоянии. Как это исправить?
from tkinter import *
from tkinter import messagebox
# Window
calcWin = Tk()
calcWin.title('Calculator')
calcWin.geometry('350x450')
calcWin.wm_attributes('-alpha', 1)
calcWin.resizable(width=False, height=False)
# Import Function
def InsertData(event):
text = event.widget.cget('text')
lineEntry.insert(END, text)
def result(eventResult):
result = lineEntry.get().strip()
lineEntry.delete(0, END)
try:
lineEntry.insert(END, eval(result))
except:
messagebox.showerror(message='Error')
lineEntry.delete(0, END)
def delete(d):
lineEntry.delete(0, END)
def Back(b):
lineEntry.delete(-1)
def Options(о):
messagebox.showinfo(message='Soon')
# Enter line
lineEntry = Entry(calcWin, font=2.5, bg='white')
lineEntry.place(relwidth=1, relheight=0.15, relx=0, rely=0)
# Buttons
'''First row'''
calcBut = Button(calcWin, bg='gray', text='Del', font=0.4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.07, rely=0.16)
calcBut.bind('<Button-1>', delete)
calcBut = Button(calcWin, bg='gray', text='Back', font=0.4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.28, rely=0.16)
calcBut.bind('<Button-1>', Back)
calcBut = Button(calcWin, bg='orange', text='+', font=4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.7, rely=0.16)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='OP', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.49, rely=0.16)
calcBut.bind('<Button-1>', Options)
'''Second row'''
calcBut = Button(calcWin, bg='gray', text='7', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.07, rely=0.325)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='8', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.28, rely=0.325)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='9', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.49, rely=0.325)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='orange', text='-', font=4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.7, rely=0.325)
calcBut.bind('<Button-1>', InsertData)
'''Third row'''
calcBut = Button(calcWin, bg='gray', text='4', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.07, rely=0.492)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='5', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.28, rely=0.492)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='6', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.49, rely=0.492)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='orange', text='*', font=4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.7, rely=0.492)
calcBut.bind('<Button-1>', InsertData)
'''Fourth row'''
calcBut = Button(calcWin, bg='gray', text='1', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.07, rely=0.657)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='2', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.28, rely=0.657)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='3', font=2)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.49, rely=0.657)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='orange', text='/', font=4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.7, rely=0.657)
calcBut.bind('<Button-1>', InsertData)
'''Fifth row'''
calcBut = Button(calcWin, bg='gray', text='0', font=2)
calcBut.place(relwidth=0.41, relheight=0.16, relx=0.07, rely=0.825)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='gray', text='.', font=50)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.49, rely=0.825)
calcBut.bind('<Button-1>', InsertData)
calcBut = Button(calcWin, bg='orange', text='=', font=4)
calcBut.place(relwidth=0.2, relheight=0.16, relx=0.7, rely=0.825)
calcBut.bind('<Button-1>', result)
calcWin.mainloop()