如何在macOS上全屏显示tkinter应用程序? [英] How do I display a tkinter application in fullscreen on macOS?

查看:112
本文介绍了如何在macOS上全屏显示tkinter应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在学习python,我正在尝试使一个窗口全屏显示,这已经实现了,但是现在我想摆脱顶部的标题栏.当前它看起来像下面的图像,但我希望它也可以通过顶部的Mac顶部工具栏(如启动屏幕)查看.

I am just learning python, and I am trying to make a window go full screen, which I have achieved, but I am now wanting to get rid of the title bar across the top. It currently looks like the image below, but I want it to also go over the Mac top toolbar at top (like a splash screen).

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')

试试看.它应该可以解决问题.

Try this instead. It should do the trick.

from tkinter import *
root = Tk()

root.wm_attributes('-fullscreen','true')

def quitApp():
    root.destroy()

button = Button(text = 'QUIT', command = quitApp).pack()

root.mainloop()

如果由于MacOS而无法解决问题,请查看此链接有一些如何在tkinter中管理mack窗口的示例.而且我相信您可能需要获得无边框的全屏显示.

If this does not work because of the MacOS then take a look at this link This useful page has sever examples of how to manage mack windows in tkinter. And I believe what you may need to get borderless fullscreen.

这可能是您需要的代码:

This bit of code might be what you need:

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

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

Note: If you do use this option then you will need to remove root.wm_attributes('-fullscreen','true') from your code or just comment it out.

更新:

还有tkinter 8.5+的另一段代码.

There is also another bit of code for tkinter 8.5+.

如果您将python与tkinter 8.5或更高版本配合使用:

If you are using python with tkinter 8.5 or newer:

root.wm_attributes('-fullscreen', 1)

这篇关于如何在macOS上全屏显示tkinter应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆