2017-05-10 52 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,所以不幸的是我無法調試這些方法來知道哪一個最適合。試試看,並讓我知道:) –