1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
""" Demonstration of the Pmw OptionMenu megawidget.
"""
if __name__ == '__main__':
# Import Pmw from the sibling directory.
import sys
sys.path[:0] = ['../../..']
import Tkinter
import Pmw
from Tkconstants import *
class Demo:
def __init__(self, parent):
self._var = Tkinter.StringVar ( '' )
self.menu2 = Pmw.OptionMenu ( parent,
labelpos = 'w',
labelmargin = 10,
label_text = 'Choose make :',
variable = self._var,
items = ( 'ford', 'toyota', 'bmw', 'volvo' )
)
self.menu2.pack ( fill = X, padx = 10, pady = 10 )
self.menu1 = Pmw.OptionMenu ( parent,
labelpos = 'n',
command = self._callback,
label_text = 'Choose type :',
items = [ 'sedan', 'coupe', 'sports car' ],
direction = 'right')
self.menu1.pack ( fill = X, padx = 10, pady = 10 )
def _callback( self, tag ):
print 'You have chosen a %s %s' % (self._var.get(), tag)
######################################################################
# Create demo in root window for testing.
if __name__ == '__main__':
root = Tkinter.Tk()
Pmw.initialise(root, fontScheme = 'pmw1')
root.title('Pmw EXAMPLE demonstration')
exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
exitButton.pack(side = 'bottom')
widget = Demo(root)
root.mainloop()
|