This could be a source of performance problems in cer-tain environments.. To circumvent these and other problems you may use alternative approaches.. Personally, I prefer not to use the
Trang 1114 C H A P T E R 6 E V E N T S , B I N D I NG S A N D C A L L B A C K S
3 Where validation requires complex calculations and access to servers and databases, etc, the processing load can be high This could be a source of performance problems in cer-tain environments
To circumvent these and other problems you may use alternative approaches Of course, your application may not use Pmw widgets, so yet another approach may be required
Personally, I prefer not to use the built-in validation in Pmw widgets If the action of formatting the content of the widget requires a redraw, you may observe annoying display glitches, particularly if the system is heavily loaded; these may distract the user The following method avoids these problems
To avoid validating every keystroke (which is how the Pmw EntryField manages data input), we will arrange for validation to be done in the following cases:
1 When the user moves the mouse pointer out of the current field
2 When the focus is moved from the field using the TAB key
3 When the ENTER key is pressed
Validating this way means that you don’t get false errors as an input string is built up In figure 6.3, for example, entering 192.311.40.10 would only raise a validation error when the field was left or if RETURN was pressed, thereby reducing operator confusion and CPU overhead
import string
from Tkinter import *
from validation import *
Example_6_8.py
Note
Figure 6.3 Data verification:
error dialogs