I have entry boxes in my code. I would want my code to check if what has been entered in the entry boxes meets the condition, if not it outputs an error message. if the conditions are met it goes ahead to make the computations. My problems is the message box is working correctly if conditions are not met but an error if popping once the conditions are met. There are no computations.
I am getting the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\BW345KB\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\BW345KB\OneDrive - EY\Documents\My Work\My Projects\JULES PROVMAT IMPAIRMENT App\prov_matrix.py", line 199, in prov_result
cond_tw = eval(tw)
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
You can refer to picture if the the error is not clear.
dd = self.dd.get()
tot = self.tot.get()
on = self.one.get()
tt = self.thirty.get()
sx = self.sixty.get()
nn = self.ninety.get()
tw = self.twenty.get()
cur = self.curr.get()
#for conditions
cond_dd = eval(dd)
cond_tw = eval(tw)
if (cond_tw > 0 and cond_dd == 90):
messagebox.showwarning("Error", "Your Definition of Default Is " + dd + " Days Past Due")
else:
up1 = eval(tot) - eval(cur) #paid total - current
up2 = up1 - eval(on) #paid current - 1-30
up3 = up2 - eval(tt) #paid 1-30 - 31-60
up4 = up3 - eval(sx) #paid 31-60 - 61-90
up5 = up4 - eval(nn) #written off
Based on my understanding of the question from the provided resources, which lack complete code and as said by @jasonharper do not have a minimal reproducible example, the following seems to be a possible solution.
As @jasonharper pointed out it seems like the tw is an empty string and thus when passed through the eval function python throws an EOF(End of file) exception.
I think the need here is to try the statement and catch the exception, and if an exception is caught we prompt the user that the string entered is empty i.e. -: ''.
Like so -:
dd = self.dd.get()
tot = self.tot.get()
on = self.one.get()
tt = self.thirty.get()
sx = self.sixty.get()
nn = self.ninety.get()
tw = self.twenty.get()
cur = self.curr.get()
#for conditions
try :
cond_dd = eval(dd)
cond_tw = eval(tw)
except Exception :
messagebox.showwarning("Error", "You have provided no condition for either dd or tw.")
if (cond_tw > 0 and cond_dd == 90):
messagebox.showwarning("Error", "Your Definition of Default Is " + dd + " Days Past Due")
else:
up1 = eval(tot) - eval(cur) #paid total - current
up2 = up1 - eval(on) #paid current - 1-30
up3 = up2 - eval(tt) #paid 1-30 - 31-60
up4 = up3 - eval(sx) #paid 31-60 - 61-90
up5 = up4 - eval(nn) #written off