[wxPython-users] Get a valur for make some calculates
Mike Rooney
mxr at qvii.com
Tue Apr 3 10:39:45 PDT 2007
Andrea wrote:
> Hi all,
>
> I have a little gui that provide 4 textctrl for insert some data.
> After that the user insert the data I would like to do some operation
> with this data like a * b = c but I receive some type error because I
> don't have a int variables.
>
> How can I get the value from GetValue() function and use thus like
> integer or float number for do the calculates?
>
> ---Code---
> ...
> ...
> self.local = wx.TextCtrl(self.panel, -1, '', pos = (200, 45))
> self.scontolocal = wx.TextCtrl(self.panel, -1, '', pos = (200, 75))
> ...
> ...
> def OnCalculate(self, event):
> tot_local = self.local.GetValue()
> scontolocal_mr = self.scontolocal.GetValue()
> sconto = (tot_local * scontolocal_mr)/100
>
All you need to do is cast these to ints, which can be done with the
int() method. float() also exists for numbers with decimals. So:
tot_local = int(self.local.GetValue())
scontolocal_mr = int(self.scontolocal.GetValue())
You could also be using the new properties to access the value, like
tot_local = int(self.local.Value)
scontolocal_mr = int(self.scontolocal.Value)
which I personally prefer.
- Mike
More information about the wxpython-users
mailing list