更新时间:2022-02-10 04:08:43
你不应该在 python 2 或 python 3 中使用 tk_menuBar
.该函数的文档字符串是这样说的:
You should not be using tk_menuBar
in either python 2 or 3. The docstring for that function says this:
"""请勿使用.在 Tk 3.6 及更早版本中需要."""
"""Do not use. Needed in Tk 3.6 and earlier."""
注意:tk 3.6 在 90 年代初就过时了.
Note: tk 3.6 went obsolete back in the early 90's.
无法将菜单附加到 Frame
小部件.您可以添加 Menubutton
的实例来模拟菜单栏,但不会得到真正的菜单栏.
There is no way to attach a menu to a Frame
widget. You can add instances of Menubutton
to simulate a menubar, but you won't get a real menubar.
您可以通过配置menu
属性将Menu
附加到根窗口或Toplevel
的实例.
You can attach a Menu
to the root window or to instances of Toplevel
by configuring the menu
attribute.
import tkinter as tk
root = tk.Tk()
menubar = tk.Menu()
fileMenu = tk.Menu()
editMenu = tk.Menu()
viewMenu = tk.Menu()
menubar.add_cascade(label="File", menu=fileMenu)
menubar.add_cascade(label="Edit", menu=editMenu)
menubar.add_cascade(label="View", menu=viewMenu)
root.configure(menu=menubar)
root.mainloop()