擅长:python、mysql、java
<p>答案几乎是完美的,只需添加一点就可以删除整个字符串。
只有在插入文本时才应检查浮动</p>
<pre><code>def validate_float(self, action, index, value_if_allowed,
prior_value, text, validation_type, trigger_type, widget_name):
# action=1 -> insert
if(action=='1'):
if text in '0123456789.-+':
try:
float(value_if_allowed)
return True
except ValueError:
return False
else:
return False
else:
return True
</code></pre>