Line | |
---|
1 | from Tkinter import * |
---|
2 | |
---|
3 | root = Tk() |
---|
4 | |
---|
5 | def hello(): |
---|
6 | print "hello!" |
---|
7 | |
---|
8 | menubar = Menu(root) |
---|
9 | |
---|
10 | # create a pulldown menu, and add it to the menu bar |
---|
11 | filemenu = Menu(menubar, tearoff=0) |
---|
12 | filemenu.add_command(label="Open", command=hello) |
---|
13 | filemenu.add_command(label="Save", command=hello) |
---|
14 | filemenu.add_separator() |
---|
15 | filemenu.add_command(label="Exit", command=root.quit) |
---|
16 | menubar.add_cascade(label="File", menu=filemenu) |
---|
17 | |
---|
18 | # create more pulldown menus |
---|
19 | editmenu = Menu(menubar, tearoff=0) |
---|
20 | editmenu.add_command(label="Cut", command=hello) |
---|
21 | editmenu.add_command(label="Copy", command=hello) |
---|
22 | editmenu.add_command(label="Paste", command=hello) |
---|
23 | menubar.add_cascade(label="Edit", menu=editmenu) |
---|
24 | |
---|
25 | helpmenu = Menu(menubar, tearoff=0) |
---|
26 | helpmenu.add_command(label="About", command=hello) |
---|
27 | menubar.add_cascade(label="Help", menu=helpmenu) |
---|
28 | |
---|
29 | # display the menu |
---|
30 | root.config(menu=menubar) |
---|
31 | |
---|
32 | |
---|
33 | root.mainloop() |
---|
34 | root.destroy() |
---|
Note: See
TracBrowser
for help on using the repository browser.