Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | title = 'Pmw error handling demonstration' |
2 | ||
3 | # Import Pmw from this directory tree. | |
4 | import sys | |
5 | sys.path[:0] = ['../../..'] | |
6 | ||
7 | import string | |
8 | import Tkinter | |
9 | import Pmw | |
10 | ||
11 | class 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. | |
34 | if __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() |