I have created a GUI calculator (a screen shot included) and when a button is pressed it adds text to the textctrl so that the equation is displayed to the user. when the user presses enter it takes that text and runs it usesing eval then prints using SetValue but if i run a problem in the texctrl like 5/6 it comes out as 0 how do i make that a float
def eenter(self,e):
a=self.box.GetValue()
answer=eval(a)
ans=str(answer)
self.box.SetValue(ans)
Place at the top of your file:
from __future__ import division
This redefines the meaning of /
so it is always floating point division. (Integer division is //
.)
For more information on what this means, see PEP 238.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With