8e22e53b19563ee0425842ef24d7061d332dc5aa
title
= 'Pmw.MenuBar demonstration'
# Import Pmw from this directory tree.
sys
.path
[:0] = ['../../..']
def __init__(self
, parent
):
self
.balloon
= Pmw
.Balloon(parent
)
# Create and pack the MenuBar.
menuBar
= Pmw
.MenuBar(parent
,
# Add some buttons to the MenuBar.
menuBar
.addmenu('File', 'Close this window or exit')
menuBar
.addmenuitem('File', 'command', 'Close this window',
command
= PrintOne('Action: close'),
menuBar
.addmenuitem('File', 'separator')
menuBar
.addmenuitem('File', 'command', 'Exit the application',
command
= PrintOne('Action: exit'),
menuBar
.addmenu('Edit', 'Cut, copy or paste')
menuBar
.addmenuitem('Edit', 'command', 'Delete the current selection',
command
= PrintOne('Action: delete'),
menuBar
.addmenu('Options', 'Set user preferences')
menuBar
.addmenuitem('Options', 'command', 'Set general preferences',
command
= PrintOne('Action: general options'),
# Create a checkbutton menu item.
self
.toggleVar
= Tkinter
.IntVar()
# Initialise the checkbutton to 1:
menuBar
.addmenuitem('Options', 'checkbutton', 'Toggle me on/off',
command
= self
._toggleMe
,
variable
= self
.toggleVar
)
menuBar
.addcascademenu('Options', 'Size',
'Set some other preferences', traverseSpec
= 'z', tearoff
= 1)
for size
in ('tiny', 'small', 'average', 'big', 'huge'):
menuBar
.addmenuitem('Size', 'command', 'Set size to ' + size
,
command
= PrintOne('Action: size ' + size
),
menuBar
.addmenu('Help', 'User manuals', side
= 'right')
menuBar
.addmenuitem('Help', 'command', 'About this application',
command
= PrintOne('Action: about'),
# Create and pack the main part of the window.
self
.mainPart
= Tkinter
.Label(parent
,
text
= 'This is the\nmain part of\nthe window',
self
.mainPart
.pack(fill
= 'both', expand
= 1)
# Create and pack the MessageBar.
self
.messageBar
= Pmw
.MessageBar(parent
,
self
.messageBar
.pack(fill
= 'x', padx
= 10, pady
= 10)
self
.messageBar
.message('state', 'OK')
buttonBox
= Pmw
.ButtonBox(parent
)
buttonBox
.pack(fill
= 'x')
buttonBox
.add('Disable\nall', command
= menuBar
.disableall
)
buttonBox
.add('Enable\nall', command
= menuBar
.enableall
)
buttonBox
.add('Create\nmenu', command
= self
.add
)
buttonBox
.add('Delete\nmenu', command
= self
.delete
)
buttonBox
.add('Create\nitem', command
= self
.additem
)
buttonBox
.add('Delete\nitem', command
= self
.deleteitem
)
# Configure the balloon to displays its status messages in the
self
.balloon
.configure(statuscommand
= self
.messageBar
.helpmessage
)
print 'Toggle value:', self
.toggleVar
.get()
if len(self
.testMenuList
) == 0:
num
= self
.testMenuList
[-1]
self
.testMenuList
.append(num
)
self
.menuBar
.addmenu(name
, 'This is ' + name
)
if len(self
.testMenuList
) == 0:
num
= self
.testMenuList
[0]
self
.menuBar
.deletemenu(name
)
if len(self
.testMenuList
) == 0:
num
= self
.testMenuList
[-1]
menuName
= 'Menu%d' % num
menu
= self
.menuBar
.component(menuName
+ '-menu')
if menu
.index('end') is None:
label
= menu
.entrycget('end', 'label') + 'X'
self
.menuBar
.addmenuitem(menuName
, 'command', 'Help for ' + label
,
command
= PrintOne('Action: ' + menuName
+ ': ' + label
),
if len(self
.testMenuList
) == 0:
num
= self
.testMenuList
[-1]
menuName
= 'Menu%d' % num
menu
= self
.menuBar
.component(menuName
+ '-menu')
if menu
.index('end') is None:
self
.menuBar
.deletemenuitems(menuName
, 0)
def __init__(self
, text
):
######################################################################
# Create demo in root window for testing.
if __name__
== '__main__':
exitButton
= Tkinter
.Button(root
, text
= 'Exit', command
= root
.destroy
)
exitButton
.pack(side
= 'bottom')