2017-05-10 53 views
1

我正在寻找一种方法来创建全屏窗口并且不显示控制台(或边框),并且在按下“转义”按钮时转义全屏。我试图将扩展名从'py'重命名为'pyw',但它并没有隐藏侧边栏as some suggestedpython全屏无控制台/边框

这里是我的代码,以最大化窗口,但它并不隐藏控制台:

def __init__(master): #I'm using tkinter for my GUI 
    master = master 
    width, height = master.winfo_screenwidth(), master.winfo_screenheight() 
    master.geometry("%dx%d+0+0" % (width, height)) 

此外,我需要使用脚本Mac和Windows上,是他们,如果我的工作有所不同需要隐藏控制台?

我试过overrideredirect(True),但它不允许我使用键盘,这是我的任务所必需的。我也尝试过wm_attributes('-fullscreen', True),但它并没有创建完整的全屏幕,在Mac Taskbar存在的顶部是空的地方。 enter image description here

那么有没有什么方法可以让我在没有工具栏(MacOS)的情况下使用全屏,并且键盘可以工作?

谢谢!

回答

1

这个怎么样的屏幕分辨率:

from Tkinter import * 
import ttk 

def escape(root): 
     root.geometry("200x200") 

def fullscreen(root): 
     width, height = root.winfo_screenwidth(), root.winfo_screenheight() 
     root.geometry("%dx%d+0+0" % (width, height)) 

master = Tk() 
width, height = master.winfo_screenwidth(), master.winfo_screenheight() 
master.geometry("%dx%d+0+0" % (width, height)) 
master.bind("<Escape>", lambda a :escape(master)) 
#Added this for fun, when you'll press F1 it will return to a full screen. 
master.bind("<F1>", lambda b: fullscreen(master)) 
master.mainloop() 

而这对于没有边界(由here拍摄):

import tkinter as tk 
root = tk.Tk() 
root.attributes('-alpha', 0.0) #For icon 
#root.lower() 
root.iconify() 
window = tk.Toplevel(root) 
window.geometry("100x100") #Whatever size 
window.overrideredirect(1) #Remove border 
#window.attributes('-topmost', 1) 
#Whatever buttons, etc 
close = tk.Button(window, text = "Close Window", command = lambda: root.destroy()) 
close.pack(fill = tk.BOTH, expand = 1) 
window.mainloop() 

为控制台,唯一的解决办法是将文件保存为。 pyw,因为你已经阅读过。您也可以尝试使用overrideredirect(1)覆盖Tk函数,但这会更复杂。

希望这会帮助你,Yahli。

+1

谢谢Mr.Yahli! 'overrideredirect(1)'确实使窗口全屏。但它似乎只适用于Windows,但不适用于MacOS(顶部工具栏仍显示)。你知道Mac上是否有任何工作吗? – Kay

+0

很高兴我可以帮忙,考虑接受我的答案,如果你发现它足够好:)关于你的问题 - 我会试试这个'self.tk._w.wm_attributes(fullscreen ='true')'这个'tl.tk .call(“:: tk :: unsupported :: MacWindowStyle”,“style”,tl._w,“plain”,“none”)'(我把它从[here](https://bytes.com/topic /蟒/答案/ 825270-Tkinter的全屏-MAC-OS-X))。我不拥有Mac,所以不幸的是我无法调试这些方法来知道哪一个最适合。试试看,并让我知道:) –