Three types of data entry
fields appear in breezypythongui: IntegerField, and FloatField, and TextField. As
the names imply, each type of field is suited for the input and output of a
specific type of data. In the case
of the numeric fields, conversion between numbers and text is handled
internally within the field object.
Thus, the input method getNumber returns a number, whereas the output method setNumber
expects a numeric argument, when used with the numeric fields. The FloatField method setPrecision is available to modify the precision used to
display numbers. The methods getText and setText are
used to read and write strings with text fields. The data entry field methods are
summarized in the next table:
Field
Type |
Method |
What it
does |
IntegerField, FloatField |
getNumber() |
Returns (as input) the number contained in the
field. |
setNumber(number) |
Outputs the number to the field. |
|
FloatField |
setPrecision(width) |
Sets the number of digits to display to right of
the decimal point. |
TextField |
getText() |
Returns (as input) the string contained in the
field. |
setText(text) |
Outputs the string to the field. |
To make a data field output
only, to prevent the user from editing its contents, the programmer can set its
state attribute to the tkinter constant "readonly".
Note that the input method
getNumber raises an exception if the user has entered a
number with an invalid format (such as bad digits). This type of error can be trapped under
program control with a try-except statement (see Message Boxes).