我只是在学习python,我正在尝试使一个窗口全屏显示,这是我已经实现的,但是现在我想摆脱顶部的标题栏.当前它看起来像下面的图像,但我希望它也可以通过顶部Mac顶部的工具栏(如启动屏幕)查看.
<code>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()
</code>
解决方法:
我相信你要做的就是使用
root.wm_attributes(‘-fullscreen’,’true’)
试试这个吧.它应该可以解决问题.
<code>from tkinter import *
root = Tk()
root.wm_attributes('-fullscreen','true')
def quitApp():
root.destroy()
button = Button(text = 'QUIT', command = quitApp).pack()
root.mainloop()
</code>
如果由于MacOS而无法解决问题,请查看此link.这个有用的页面提供了一些示例,介绍了如何在tkinter中管理mack窗口.而且我相信您可能需要获得无边框的全屏显示.
这部分代码可能是您需要的:
<code>root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
</code>
注意:如果确实使用此选项,则需要从代码中删除root.wm_attributes(‘-fullscreen’,’true’)或仅对其进行注释.
更新:
tkinter 8.5还有另外一点代码.
如果您将python与tkinter 8.5或更高版本配合使用:
<code>root.wm_attributes('-fullscreen', 1)
</code>
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!