python3 GUI- 下拉菜单
from tkinter import *
def CallOn():
print('hello')
root = Tk()
root.geometry('500x200')
M = Menu(root)
menubar = Menu(root)
content = [['New File', 'Open File', 'Save', 'Setting', 'Exit'], ['Undo', 'Copy', 'Cut', 'Paste', 'Find'],
['Tool bar', 'Tool button'], ['Class', 'Back'], ['Reformat code', 'move down', 'move up'],
['External tool', 'development'], ['Commit', 'update'],
['close', 'close all', 'close other', 'close left', 'close right'], ['help', 'about']]
Main = ['File', 'Edit', 'View', 'Navigate', 'Code', 'Tools', 'VCS', 'Window', 'Help']
for i in range(len(Main)):
# 新建一个空的菜单,将menubar的menu属性指定为filemenu,即filemenu为menubar的下拉菜单
filemenu = Menu(menubar, tearoff=0)
for k in content[i]:
filemenu.add_command(label=k, command=CallOn)
menubar.add_cascade(label=Main[i], menu=filemenu)
root['menu'] = menubar
root.mainloop()
执行结果: