[英]How can I force the Menu to be in the window rather than the OSX default Tkinter
I'm trying to create a window that has a menu bar built into it, but whenever I implement a Tkinter code that creates a menu, it appears at the top next to the Apple logo.我正在尝试创建一个内置菜单栏的 window,但每当我执行创建菜单的 Tkinter 代码时,它都会出现在顶部的 Apple 徽标旁边。 How can I make it so that it appears directly in the Tkinter window instead of the OSX menubar?我怎样才能让它直接出现在 Tkinter window 而不是 OSX 菜单栏中?
Here's the code I have so far:这是我到目前为止的代码:
import tkinter as tk
from tkinter.filedialog import askopenfilename
def NewFile():
print("New File!")
def OpenFile():
name = askopenfilename()
print(name)
def About():
print("This is a simple example of a menu")
root = tk.Tk()
menu = tk.Menu(root)
root.config(menu=menu)
filemenu = tk.Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=NewFile)
filemenu.add_command(label="Open...", command=OpenFile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
helpmenu = tk.Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=About)
tk.mainloop()
Any and all help would be appreciated.任何和所有帮助将不胜感激。 Thanks.谢谢。
You can't do what you want.你不能为所欲为。 When you configure a menu for a window there is no way to get non-native behavior.当您为 window 配置菜单时,无法获得非本机行为。
What you can do instead is create a frame, and in the frame you can add Menubutton
widgets.您可以做的是创建一个框架,您可以在该框架中添加Menubutton
小部件。 The behavior won't be exactly the same, but with some work you can create custom bindings to mimic menubar behavior.行为不会完全相同,但通过一些工作,您可以创建自定义绑定来模仿菜单栏行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.