Q:

How to get a pygtk entry accept only floats?

I want the user to be able to type only a float (that is, numbers from 0 to 9 and the decimal point should show, other characters should not). How can I do that ?
edit
I need to get values like "4" or "3.5" or ".9", nothing like "10e23"
Inconsistent values should also be rejected, such as "10.12.45" ...

A:

I've finally an acceptable answer thanks to SO question "How to extract a floating number from a string in Python"
    numeric_const_pattern = r"""
    [-+]? # optional sign
    (?:
        (?: \d* \. \d+ ) # .1 .12 .123 etc 9.1 etc 98.1 etc
        |
        (?: \d+ \.? ) # 1. 12. 123. etc 1 12 123 etc
    )
    # followed by optional exponent part if desired
    (?: [Ee] [+-]? \d+ ) ?
    """
    self.rx = re.compile(numeric_const_pattern, re.VERBOSE)

in the init part,
and :
def validate_float(self, widget, entry):
    entry_text = entry.get_text()
    newtext = self.rx.findall(entry_text)
    if len(newtext) :
        entry.set_text(newtext[0])
    else:
        entry.set_text("")

connected to the "changed" event of the entry. Many thanks to all those who helped.

