Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / ErrorHandling.py
CommitLineData
920dae64
AT
1title = 'Pmw error handling demonstration'
2
3# Import Pmw from this directory tree.
4import sys
5sys.path[:0] = ['../../..']
6
7import string
8import Tkinter
9import Pmw
10
11class Demo:
12 def __init__(self, parent):
13 # Create two buttons to generate errors.
14 w = Tkinter.Button(parent, text = 'Click here to generate\n' +
15 'an error in a command callback.', command = self.execute)
16 w.pack(padx = 8, pady = 8)
17
18 w = Tkinter.Button(parent, text = 'Click here to generate\n' +
19 'an error in a callback called\nfrom an event binding.')
20 w.pack(padx = 8, pady = 8)
21 w.bind('<ButtonRelease-1>', self.execute)
22 w.bind('<Key-space>', self.execute)
23
24 def execute(self, event = None):
25 self._error()
26
27 def _error(self):
28 # Divide by zero
29 1/0
30
31######################################################################
32
33# Create demo in root window for testing.
34if __name__ == '__main__':
35 root = Tkinter.Tk()
36 Pmw.initialise(root)
37 root.title(title)
38
39 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
40 exitButton.pack(side = 'bottom')
41 widget = Demo(root)
42 root.mainloop()