9.Menubar菜单
制作菜单栏,file,edit
tk.Menu() 制作一个菜单bar,
然后再tk.Menu,增加filemenu,
menubar.add_cascade增加选项
filemenu.add_command增加
import tkinter as tk
window = tk.Tk()
window.title("my window")
window.geometry("200x200")
l = tk.Label(window, text='', bg='yellow')
l.pack()
counter = 0
def do_job():
global counter
l.config(text='do ' + str(counter))
counter += 1
menubar = tk.Menu(window)
filemenu = tk.Menu(menubar, tearoff=0) # tearoff能不能被分开
menubar.add_cascade(label='File', menu=filemenu) # 加选项
filemenu.add_command(label='New', command=do_job)
filemenu.add_command(label='Open', command=do_job)
filemenu.add_command(label='Save', command=do_job)
filemenu.add_separator()
filemenu.add_command(label='Exit', command=window.quit