如何在 macOS 上全屏显示 tkinter 应用程序?
How do I display a tkinter application in fullscreen on macOS?
我刚刚开始学习 python,我正在尝试让 window 进入全屏,我已经做到了,但我现在想去掉整个屏幕的标题栏最佳。它目前看起来像下图,但我希望它也越过顶部的 Mac 顶部工具栏(如启动画面)。
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.attributes('-topmost', True)
root.overrideredirect(True)
def quitApp():
# mlabel = Label (root, text = 'Close').pack()
root.destroy()
# placing the button on my window
button = Button(text = 'QUIT', command = quitApp).pack()
我相信你想做的是使用
root.wm_attributes('-fullscreen','true')
试试这个。它应该可以解决问题。
from tkinter import *
root = Tk()
root.wm_attributes('-fullscreen','true')
def quitApp():
root.destroy()
button = Button(text = 'QUIT', command = quitApp).pack()
root.mainloop()
如果这在 MacOS 上不起作用,请查看此 link 这个有用的页面有多个示例,说明如何在 tkinter 中管理 mack windows。我相信您可能需要什么才能获得无边框全屏。
这段代码可能是您需要的:
root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
注意:如果您使用此选项,则需要从代码中删除 root.wm_attributes('-fullscreen','true')
或将其注释掉。
更新:
还有一些 tkinter 8.5+ 的代码。
如果您将 python 与 tkinter 8.5 或更新版本一起使用:
root.wm_attributes('-fullscreen', 1)
我刚刚开始学习 python,我正在尝试让 window 进入全屏,我已经做到了,但我现在想去掉整个屏幕的标题栏最佳。它目前看起来像下图,但我希望它也越过顶部的 Mac 顶部工具栏(如启动画面)。
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.attributes('-topmost', True)
root.overrideredirect(True)
def quitApp():
# mlabel = Label (root, text = 'Close').pack()
root.destroy()
# placing the button on my window
button = Button(text = 'QUIT', command = quitApp).pack()
我相信你想做的是使用
root.wm_attributes('-fullscreen','true')
试试这个。它应该可以解决问题。
from tkinter import *
root = Tk()
root.wm_attributes('-fullscreen','true')
def quitApp():
root.destroy()
button = Button(text = 'QUIT', command = quitApp).pack()
root.mainloop()
如果这在 MacOS 上不起作用,请查看此 link 这个有用的页面有多个示例,说明如何在 tkinter 中管理 mack windows。我相信您可能需要什么才能获得无边框全屏。
这段代码可能是您需要的:
root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
注意:如果您使用此选项,则需要从代码中删除 root.wm_attributes('-fullscreen','true')
或将其注释掉。
更新:
还有一些 tkinter 8.5+ 的代码。
如果您将 python 与 tkinter 8.5 或更新版本一起使用:
root.wm_attributes('-fullscreen', 1)