【问题标题】:How do I display a tkinter application in fullscreen on macOS?如何在 macOS 上全屏显示 tkinter 应用程序?
【发布时间】:2017-06-03 22:07:47
【问题描述】:

我刚刚学习 python,我正在尝试让一个窗口全屏显示,我已经实现了,但我现在想摆脱顶部的标题栏。它目前看起来像下面的图像,但我希望它也可以越过顶部的 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()

【问题讨论】:

  • overrideredirect 方法适用于 windows,但不确定如何/是否适用于 mac。
  • 我试过了,但没有做任何事情(也许我做错了)

标签: python macos python-2.7 tkinter fullscreen


【解决方案1】:

我相信你想做的就是使用

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 窗口。而且我相信您可能需要什么才能获得无边框全屏。

这段代码可能就是你需要的:

root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")

注意:如果您确实使用此选项,则需要从代码中删除 root.wm_attributes('-fullscreen','true') 或将其注释掉。

更新:

tkinter 8.5+ 还有一段代码。

如果您在 tkinter 8.5 或更高版本中使用 python:

root.wm_attributes('-fullscreen', 1)

【讨论】:

  • 嗨,Mac 工具栏去掉了(如果是这样的话),但仍然显示应用程序标题栏
猜你喜欢
  • 1970-01-01
  • 2011-12-19
  • 1970-01-01
  • 2010-10-05
  • 1970-01-01
  • 1970-01-01
  • 2015-06-16
相关资源
最近更新 更多