Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / OptionMenu.py
CommitLineData
920dae64
AT
1title = 'Pmw.OptionMenu 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 OptionMenu megawidgets.
13 # The first one has a textvariable.
14 self.var = Tkinter.StringVar()
15 self.var.set('steamed')
16 self.method_menu = Pmw.OptionMenu(parent,
17 labelpos = 'w',
18 label_text = 'Choose method:',
19 menubutton_textvariable = self.var,
20 items = ['baked', 'steamed', 'stir fried', 'boiled', 'raw'],
21 menubutton_width = 10,
22 )
23 self.method_menu.pack(anchor = 'w', padx = 10, pady = 10)
24
25 self.vege_menu = Pmw.OptionMenu (parent,
26 labelpos = 'w',
27 label_text = 'Choose vegetable:',
28 items = ('broccoli', 'peas', 'carrots', 'pumpkin'),
29 menubutton_width = 10,
30 command = self._printOrder,
31 )
32 self.vege_menu.pack(anchor = 'w', padx = 10, pady = 10)
33
34 self.direction_menu = Pmw.OptionMenu (parent,
35 labelpos = 'w',
36 label_text = 'Menu direction:',
37 items = ('flush', 'above', 'below', 'left', 'right'),
38 menubutton_width = 10,
39 command = self._changeDirection,
40 )
41 self.direction_menu.pack(anchor = 'w', padx = 10, pady = 10)
42
43 menus = (self.method_menu, self.vege_menu, self.direction_menu)
44 Pmw.alignlabels(menus)
45
46 def _printOrder(self, vege):
47 # Can use 'self.var.get()' instead of 'getcurselection()'.
48 print 'You have chosen %s %s.' % \
49 (self.method_menu.getcurselection(), vege)
50
51 def _changeDirection(self, direction):
52 for menu in (self.method_menu, self.vege_menu, self.direction_menu):
53 menu.configure(menubutton_direction = direction)
54
55######################################################################
56
57# Create demo in root window for testing.
58if __name__ == '__main__':
59 root = Tkinter.Tk()
60 Pmw.initialise(root)
61 root.title(title)
62
63 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
64 exitButton.pack(side = 'bottom')
65 widget = Demo(root)
66 root.mainloop()