Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / ButtonBox.py
CommitLineData
86530b38
AT
1title = 'Pmw.ButtonBox demonstration'
2
3# Import Pmw from this directory tree.
4import sys
5sys.path[:0] = ['../../..']
6
7import Tkinter
8import Pmw
9
10class Demo:
11 def __init__(self, parent):
12 # Create and pack the ButtonBox.
13 self.buttonBox = Pmw.ButtonBox(parent,
14 labelpos = 'nw',
15 label_text = 'ButtonBox:',
16 frame_borderwidth = 2,
17 frame_relief = 'groove')
18 self.buttonBox.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
19
20 # Add some buttons to the ButtonBox.
21 self.buttonBox.add('OK', command = self.ok)
22 self.buttonBox.add('Apply', command = self.apply)
23 self.buttonBox.add('Cancel', command = self.cancel)
24
25 # Set the default button (the one executed when <Return> is hit).
26 self.buttonBox.setdefault('OK')
27 parent.bind('<Return>', self._processReturnKey)
28 parent.focus_set()
29
30 # Make all the buttons the same width.
31 self.buttonBox.alignbuttons()
32
33 def _processReturnKey(self, event):
34 self.buttonBox.invoke()
35
36 def ok(self):
37 print 'You clicked on OK'
38
39 def apply(self):
40 print 'You clicked on Apply'
41
42 def cancel(self):
43 print 'You clicked on Cancel'
44
45######################################################################
46
47# Create demo in root window for testing.
48if __name__ == '__main__':
49 root = Tkinter.Tk()
50 Pmw.initialise(root)
51 root.title(title)
52
53 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
54 exitButton.pack(side = 'bottom')
55 widget = Demo(root)
56 root.mainloop()