title
= 'Pmw.EntryField demonstration'
# Import Pmw from this directory tree.
sys
.path
[:0] = ['../../..']
def __init__(self
, parent
):
# Create and pack the EntryFields.
self
._any
= Pmw
.EntryField(parent
,
self
._real
= Pmw
.EntryField(parent
,
label_text
= 'Real (10.0 to 99.0):',
validate
= {'validator' : 'real',
'min' : 10, 'max' : 99, 'minstrict' : 0},
modifiedcommand
= self
.changed
)
self
._odd
= Pmw
.EntryField(parent
,
label_text
= 'Odd length:',
validate
= self
.custom_validate
,
self
._date
= Pmw
.EntryField(parent
,
label_text
= 'Date (in 2000):',
validate
= {'validator' : 'date',
'min' : '2000/1/1', 'max' : '2000/12/31',
'minstrict' : 0, 'maxstrict' : 0,
now
= time
.localtime(time
.time())
self
._date
2 = Pmw
.EntryField(parent
,
label_text
= 'Date (d.m.y):',
value
= '%d.%d.%d' % (now
[2], now
[1], now
[0]),
validate
= {'validator' : 'date',
'format' : 'dmy', 'separator' : '.'},
self
._time
= Pmw
.EntryField(parent
,
label_text
= 'Time (24hr clock):',
validate
= {'validator' : 'time',
'min' : '00:00:00', 'max' : '23:59:59',
'minstrict' : 0, 'maxstrict' : 0},
self
._comma
= Pmw
.EntryField(parent
,
label_text
= 'Real (with comma):',
validate
= {'validator' : 'real', 'separator' : ','},
entries
= (self
._any
, self
._real
, self
._odd
, self
._date
, self
._date
2,
entry
.pack(fill
='x', expand
=1, padx
=10, pady
=5)
self
._any
.component('entry').focus_set()
print 'Text changed, value is', self
._real
.getvalue()
print 'Return pressed, value is', self
._any
.getvalue()
# This implements a custom validation routine. It simply checks
# if the string is of odd length.
def custom_validate(self
, text
):
######################################################################
# Create demo in root window for testing.
if __name__
== '__main__':
exitButton
= Tkinter
.Button(root
, text
= 'Exit', command
= root
.destroy
)
exitButton
.pack(side
= 'bottom')