Use py_resource module
[python/dscho.git] / Demo / tkinter / matt / menu-simple.py
blob1f46e2116ae852d6f7d521547f1b002830f26dbc
1 from Tkinter import *
3 # some vocabulary to keep from getting confused. This terminology
4 # is something I cooked up for this file, but follows the man pages
5 # pretty closely
6 #
7 #
8 #
9 # This is a MENUBUTTON
10 # V
11 # +-------------+
12 # | |
14 # +------------++------------++------------+
15 # | || || |
16 # | File || Edit || Options | <-------- the MENUBAR
17 # | || || |
18 # +------------++------------++------------+
19 # | New... |
20 # | Open... |
21 # | Print |
22 # | | <------ This is a MENU. The lines of text in the menu are
23 # | | MENU ENTRIES
24 # | +---------------+
25 # | Open Files > | file1 |
26 # | | file2 |
27 # | | another file | <------ this cascading part is also a MENU
28 # +----------------| |
29 # | |
30 # | |
31 # | |
32 # +---------------+
36 def new_file():
37 print "opening new file"
40 def open_file():
41 print "opening OLD file"
44 def makeFileMenu():
45 # make menu button : "File"
46 File_button = Menubutton(mBar, {'text': 'File',
47 'underline': 0,
48 Pack: {'side': 'left',
49 'padx': '1m'}})
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...',
60 'underline': 0,
61 'command' : new_file})
64 File_button.menu.add('command', {'label': 'Open...',
65 'underline': 0,
66 'command' : open_file})
68 File_button.menu.add('command', {'label': 'Quit',
69 'underline': 0,
70 'command': 'exit'})
73 # set up a pointer from the file menubutton back to the file menu
74 File_button['menu'] = File_button.menu
76 return File_button
80 def makeEditMenu():
81 Edit_button = Menubutton(mBar, {'text': 'Edit',
82 'underline': 0,
83 Pack: {'side': 'left',
84 'padx' : '1m'}})
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
100 return Edit_button
103 #################################################
105 #### Main starts here ...
106 root = Tk()
109 # make a menu bar
110 mBar = Frame(root, {'relief': 'raised',
111 'bd': 2,
112 Pack: {'side': 'top',
113 'fill': 'x'}})
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')
126 root.mainloop()