Tải bản đầy đủ (.pdf) (1 trang)

Graphical user interfaces for Python programs Phần 3 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (157.2 KB, 1 trang )

114 CHAPTER 6 EVENTS, BINDINGS AND CALLBACKS
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

×