3 # some vocabulary to keep from getting confused. This terminology
4 # is something I cooked up for this file, but follows the man pages
14 # +------------++------------++------------+
16 # | File || Edit || Options | <-------- the MENUBAR
18 # +------------++------------++------------+
22 # | | <------ This is a MENU. The lines of text in the menu are
25 # | Open Files > | file1 |
27 # | | another file | <------ this cascading part is also a MENU
28 # +----------------| |
37 print "opening new file"
41 print "opening OLD file"
45 # make menu button : "File"
46 File_button
= Menubutton(mBar
, {'text': 'File',
48 Pack
: {'side': 'left',
51 # make the pulldown part of the File menu. The parameter passed is the master.
52 # we attach it to the File button as a python attribute called "menu" by convention.
53 # hopefully this isn't too confusing...
54 File_button
.menu
= Menu(File_button
)
56 # add an item. The first param is a menu entry type,
57 # must be one of: "cascade", "checkbutton", "command", "radiobutton", "seperator"
58 # see menu-demo-2.py for examples of use
59 File_button
.menu
.add('command', {'label': 'New...',
61 'command' : new_file
})
64 File_button
.menu
.add('command', {'label': 'Open...',
66 'command' : open_file
})
68 File_button
.menu
.add('command', {'label': 'Quit',
73 # set up a pointer from the file menubutton back to the file menu
74 File_button
['menu'] = File_button
.menu
81 Edit_button
= Menubutton(mBar
, {'text': 'Edit',
83 Pack
: {'side': 'left',
85 Edit_button
.menu
= Menu(Edit_button
)
87 # just to be cute, let's disable the undo option:
88 Edit_button
.menu
.add('command', {"label" : "Undo"} )
89 # undo is the 0th entry...
90 Edit_button
.menu
.entryconfig(0, {"state" : "disabled"})
92 # and these are just for show. No "command" callbacks attached.
93 Edit_button
.menu
.add('command', {"label" : "Cut"} )
94 Edit_button
.menu
.add('command', {"label" : "Copy"} )
95 Edit_button
.menu
.add('command', {"label" : "Paste"} )
97 # set up a pointer from the file menubutton back to the file menu
98 Edit_button
['menu'] = Edit_button
.menu
103 #################################################
105 #### Main starts here ...
110 mBar
= Frame(root
, {'relief': 'raised',
112 Pack
: {'side': 'top',
115 File_button
= makeFileMenu()
116 Edit_button
= makeEditMenu()
118 # finally, install the buttons in the menu bar.
119 # This allows for scanning from one menubutton to the next.
120 mBar
.tk_menuBar(File_button
, Edit_button
)
123 root
.title('menu demo')
124 root
.iconname('packer')