I am getting an error when I create a wx.lib.masked.TextCtrl with a mask that specifies a float and attempt to set its value.
The mask I use is '#{9}.#{3}'. The problem arises when I try to do ctrl.SetValue('23.0').
The attached sample shows the problem.
I suppose I could use a wx.lib.masked.NumCtrl, but I am curious now why this doesn't work.
Thanks for any advice.
Hank
temp.py (1.11 KB)
Hank,
Hank Knox wrote:
I am getting an error when I create a wx.lib.masked.TextCtrl with a mask that specifies a float and attempt to set its value.
The mask I use is '#{9}.#{3}'. The problem arises when I try to do ctrl.SetValue('23.0').
The value you use to set to a masked control has to have the length of the control (respecting the 9.3).
The attached sample does:
self.textCtrl1.SetValue('23.000'.zfill(self.textCtrl1._masklength))
Simplistic, but it does the trick. One would have to enhance this for the real world, or just use the numctrl.
Now, in your sample I couldn't get this to work until I saved a reference for the control, i.e. instead of 'ctrl' name change it to self.ctrl.
Why it crashes hard, i.e. without exception (at least on MS Vista) I don't know, would be nice to figure that out.
The attached sample shows the problem.
I suppose I could use a wx.lib.masked.NumCtrl, but I am curious now why this doesn't work.
As you can see from the attached that might be the better solution
, as it figures fills the control correctly.
Werner
Frame1.py (2.27 KB)
Werner,
Thanks - it didn’t occur to me to pad out the decimal part of the value
to match the mask.
Under Windows XP, Python 2.5, wxPython 2.8.1.1, I only get an
exception, not a hard lock up. Also, I didn’t have to save the
reference to ctrl. I’m not ot sure what those issues are about.
And in the end, I switched to the NumCtrl, it was actually better for
my purposes.
Thanks again.
Hank
Werner F. Bruhin wrote:
···
wxPython-users-unsubscribe@lists.wxwidgets.orgwxPython-users-help@lists.wxwidgets.org