import tkinter win = tkinter.Tk()win.title("Menu顶层菜单栏")win.geometry("800x600+600+100") #菜单条menubar =tkinter.Menu(win)win.config(menu=menubar)def func(): print("lalaa")#创建一个菜单选项menu1=tkinter.Menu(menubar,tearoff=False)#给菜单选项,添加菜单内容for item in ["Python","C","C++","OC","Swift","C#","shell", "java","JS","PHP","汇编","NodeJs","退出"]: if item=="退出": menu1.add_separator()#添加一个分割线 menu1.add_command(label=item,command=lambda :win.quit())#lambda:win.quit==win.quit else: menu1.add_command(label=item,command=func)#向菜单条上添加菜单menubar.add_cascade(label="语言",menu=menu1) menu2=tkinter.Menu(menubar,tearoff=False)menu2.add_command(label="red")menu2.add_command(label="blue")menubar.add_cascade(label="颜色",menu=menu2) win.mainloop()
原文地址:https://www.cnblogs.com/zlong123/p/10498126.html
时间: 2024-11-05 22:45:30