1 title = 'Pmw.CounterDialog demonstration'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
12 def __init__(self, parent):
13 # Create the dialog to prompt for the number of times to ring the bell.
14 self.dialog = Pmw.CounterDialog(parent,
15 label_text = 'Enter the number of times to\n' + \
16 'sound the bell (1 to 5)\n',
17 counter_labelpos = 'n',
19 counter_datatype = 'numeric',
21 {'validator' : 'numeric', 'min' : 1, 'max' : 5},
22 buttons = ('OK', 'Cancel'),
24 title = 'Bell ringing',
25 command = self.execute)
26 self.dialog.withdraw()
28 # Create button to launch the dialog.
29 w = Tkinter.Button(parent, text = 'Show counter dialog',
30 command = self.dialog.activate)
31 w.pack(padx = 8, pady = 8)
33 def execute(self, result):
34 if result is None or result == 'Cancel':
35 print 'Bell ringing cancelled'
36 self.dialog.deactivate()
38 count = self.dialog.get()
39 if not self.dialog.valid():
40 print 'Invalid entry: "' + count + '"'
42 print 'Ringing the bell ' + count + ' times'
43 for num in range(string.atoi(count)):
45 self.dialog.after(200)
47 self.dialog.deactivate()
49 ######################################################################
51 # Create demo in root window for testing.
52 if __name__ == '__main__':
57 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
58 exitButton.pack(side = 'bottom')