Re: GtkEntry only for numbers



My 2 suggestions:

a. The manual way: on losing focus, compare every character against a
period and run isdigit() on it. Optionally compare against a '+' or '-'
or
'e', depending on how you want the user to enter your float. If the
tests
pass, let the input the way it is (and maybe run atof() on the string
and
process the input). If not, regain focus on the GtkEntry and message the
user to fix the input.

b. The easy way: run strtof() on the string and see if it returns 0. If
it
does, the user either entered '0' or entered something illegal. Read
strtof's man page for more ideas.

Flavio
--

Ignacio Nodal wrote:

> Hi
>
> I want to use a GtkEntry widget, where the user should only enter float
> values.
> How can i avoid ilegal text-entries?
>
> Ignacio Nodal
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]