Menubar 菜单
作者:互联网
import tkinter as tk window = tk.Tk() window.title("daxiangcai's title") window.geometry('800x400') def createnew(): l.config(text='you have created a new file') l = tk.Label(window, text='', bg='green', width=40) l.pack() menubar = tk.Menu(window) # 菜单栏 filemenu = tk.Menu(menubar, tearoff=0) # 下拉菜单;tearoff代表菜单栏跟下拉菜单之间有没有空隙 menubar.add_cascade(label='File', menu=filemenu) # 添加下拉菜单 filemenu.add_command(label='New', command=createnew) filemenu.add_separator() # 添加分割线 filemenu.add_command(label='Exit', command=window.quit) filesubmenu = tk.Menu(filemenu) # 子下拉菜单 filemenu.add_cascade(label='More', menu=filesubmenu, underline=0) filesubmenu.add_command(label='Coming soon') editmenu = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label='Edit', menu=editmenu) editmenu.add_command(label='Copy') editmenu.add_command(label='Paste') editmenu.add_command(label='Cut') editmenu.add_separator() window.config(menu=menubar) window.mainloop()
标签:菜单,filemenu,add,label,window,command,tk,Menubar 来源: https://www.cnblogs.com/daxiangcai/p/16448813.html