简体   繁体   English

如何强制菜单位于 window 而不是 OSX 默认值 Tkinter

[英]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.

相关问题 TkInter:如何使对象出现在第二个而不是第一个窗口上? - TkInter: how can I make objects appear on my second window rather than the first? 如何堆叠按钮,而不是在Tkinter中将它们排队? - How can I stack buttons rather than queue them in Tkinter? 如何在tkinter中设置mac osx默认按钮 - How can I set the mac osx default button in tkinter 如何告诉OSX使用brew中的matplotlib,而不是默认值? - How do I tell OSX to use matplotlib from brew, rather than default? 在我的 Tkinter gui 中,我能否让我的选项菜单只显示在一个选项卡上而不是所有三个选项卡上? - Can I have my options menu display only on one tab rather than all three in my Tkinter gui? 如何更改此代码以输出颜色取决于高度的直方图,而不是我选择的默认“酷”值 - How can I change this code to output an histogram with colors depending on height rather than the default 'cool' I chose 我如何 plot 特定属性而不是时间序列中所有属性的默认值 - How can I plot specific attributes rather than default of all attributes in Time Series 如何在OSX上的Python中替换“关于Tkinter”菜单 - How to replace the “About Tkinter” menu in Python on OSX 在Mac OSX上使用Tkinter菜单删除默认的“Python”子菜单 - Remove default “Python” submenu with Tkinter Menu on Mac OSX 如何使用 tkinter 制作菜单系统? - How can I make a menu system with tkinter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM