原文
1 2 3 4 5
| mb = tkinter.Menubutton( root, bg = "red" ) mb.pack()
|
1 2 3 4 5 6 7 8
| def hello(): print ("hello ...") m = tkinter.Menu( root ) m.add_command(label = "one",command = hello) m.add_command(label = "two",command = hello) root.config(menu = m)
|
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
| def hello(): print ("hello!") menubar = tkinter.Menu(root) filemenu = tkinter.Menu(menubar, tearoff=0) filemenu.add_command(label="Open", command=hello) filemenu.add_command(label="Save", command=hello) filemenu.add_separator() filemenu.add_command(label="Exit", command=root.quit) menubar.add_cascade(label="File", menu=filemenu) editmenu = tkinter.Menu(menubar, tearoff=0) editmenu.add_command(label="Cut", command=hello) editmenu.add_command(label="Copy", command=hello) editmenu.add_command(label="Paste", command=hello) menubar.add_cascade(label="Edit", menu=editmenu) helpmenu = tkinter.Menu(menubar, tearoff=0) helpmenu.add_command(label="About", command=hello) menubar.add_cascade(label="Help", menu=helpmenu) root.config(menu=menubar)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| def hello(): print ("hello!") menu = tkinter.Menu(root, tearoff=0) menu.add_command(label="Undo", command=hello) menu.add_command(label="Redo", command=hello) frame = tkinter.Frame(root, width=212, height=212) frame.pack() def popup(event): menu.post(event.x_root, event.y_root) frame.bind("<Button-3>", popup)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| counter = 0 def update(): global counter counter = counter + 1 menu.entryconfig(0, label=str(counter)) root = Tk() menubar = Menu(root) menu = Menu(menubar, tearoff=0, postcommand=update) menu.add_command(label=str(counter)) menu.add_command(label="Exit", command=root.quit) menubar.add_cascade(label="Test", menu=menu) root.config(menu=menubar)
|
5. methods
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
| Menu(master=None, **options) __init__(master=None, **options) [ activate(index) [ add(type, **options) [ add_cascade(**options) [ add_checkbutton(**options) [ add_command(**options) [ add_radiobutton(**options) [ add_separator(**options) [ config(**options) [ delete(index1, index2=None) [ entrycget(index, option) [ entryconfig(index, **options) [ entryconfigure(index, **options) [ index(index) [ insert(index, itemType, **options) [ insert_cascade(index, **options) [ insert_checkbutton(index, **options) [ insert_command(index, **options) [ insert_radiobutton(index, **options) [ insert_separator(index, **options) [ invoke(index) [ post(x, y) [ type(index) [ unpost() [ yposition(index) [
|