Pmw.EntryField

Name

Pmw.EntryField() - entry widget with validation

Inherits

Pmw.MegaWidget

Description

This class consists of an entry widget with optional validation and an optional upper limit on the number of characters which may be entered. Built-in validation may be used, such as integer, real or alphabetic, or an external validation function may be supplied.

Options

Options for this megawidget and its base classes are described below.

command
This specifies a function to call whenever the <Return> key is pressed or invoke() is called. The default is None.

errorbackground
Specifies the background color to use when displaying invalid text (that is, when the validate function returns -1). The default is 'pink'.

invalidcommand
This is executed when invalid text is entered and the text is restored to its previous value (that is, when the validate function returns 0). The default is self.bell.

labelmargin
Initialisation option. If the labelpos option is not None, this specifies the distance between the label component and the rest of the megawidget. The default is 0.

labelpos
Initialisation option. Specifies where to place the label component. If not None, it should be a concatenation of one or two of the letters 'n', 's', 'e' and 'w'. The first letter specifies on which side of the megawidget to place the label. If a second letter is specified, it indicates where on that side to place the label. For example, if labelpos is 'w', the label is placed in the centre of the left hand side; if it is 'wn', the label is placed at the top of the left hand side; if it is 'ws', the label is placed at the bottom of the left hand side.

If None, a label component is not created. The default is None.

maxwidth
Specifies the maximum allowable width of the entry. The widget will display no more than this number of characters in the entry, regardless of what the user types. If 0, then no length restriction is imposed. The default is 0.

modifiedcommand
This is called whenever the contents of the entry has been changed due to user action or by a call to setentry(). The default is None.

validate
Specifies what kind of validation should be performed on the entry input. Must be one of the built-in validators, a function or None. The built-in validators are

 numeric           integer >= 0
 integer           any integer, negative, 0 or positive
 hexadecimal       hex number (optionally with leading 0x)
 real              number with or without a decimal point
 alphabetic        letters a-zA-Z
 alphanumeric      letters a-zA-Z and digits
 timeN             HH:MM:SS (may be negative)
 time24            HH:MM:SS (between 00:00:00 and 23:59:59)
 date_dmy          DD/MM/YY
 date_mdy          MM/DD/YY
 date_ymd          YY/MM/DD
                     - YY may be any number of digits

If validate is a function, then it will be called whenever the contents of the entry may have changed due to user action or by a call to setentry(). The function is called with one argument, being the new text as modified by the user or setentry(). It should return 1 if the text is valid. It should return 0 if the text is invalid and the entry should be restored to its previous value. It should return -1 if the text is invalid and should be displayed using the errorbackground color.

If validate is None, no validation is performed. The default is None.

value
Initialisation option. Specifies the initial contents of the entry. The default is ''.

Components

Components created by this megawidget and its base classes are described below.

entry
The widget where the user may enter text. Long text may be scrolled horizontally by dragging with the middle mouse button. By default, this component is a Tkinter.Entry.

hull
This acts as the body for the entire megawidget. Other components are created as children of the hull to further specialise the widget. By default, this component is a Tkinter.Frame.

label
If the labelpos option is not None, this component is created as a text label for the megawidget. See the labelpos option for details. Note that to set, for example, the text option of the label, you need use the label_text component option. By default, this component is a Tkinter.Label.

Methods

Only methods specific to this megawidget are described below. For a description of its inherited methods, see the manuals for its base classes. In addition, methods from Tkinter.Entry are forwarded to this megawidget's entry component.

clear()
Remove all text from the entry widget.

invoke()
Invoke the command specified by the command option as if the <Return> key had been pressed.

setentry(text)
Set the contents of the entry widget to text and carry out validation as if the text had been entered by the user.

valid()
Return true if the contents of the entry widget are valid.

Home. Pmw 0.6.2 Maintainer gregm@iname.com. 23 Feb 1998