def action(event):
flag=0
Text=event.widget.cget("text")
full_text=display.get()
if(full_text and full_text[-1] not in "+-*/" and Text not in'=1234567890'):
display.insert(END,Text)
elif(Text not in "+-*/="):
if(flag==1):
print(flag)
display.delete(0,END)
display.insert(END,Text)
flag=0
else:
display.insert(END,Text)
elif(Text == '='):
try:
display.delete(0, END)
result = str(eval(full_text))
display.insert(END, result)
flag=1
except ZeroDivisionError:
display.insert(END,"UNDEFINED")
In this code when equal is clicked flag will be 1. Then after equals result. Any number clicked it should delete and and add the text. But it is not working.
New contributor
PRAYAG V is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1