如何在 Tkinter 中顯示全屏模式?


Tkinter 預設按應用程式視窗大小顯示。但是,我們可以使用 attributes('fullscreen', True) 方法顯示一個全屏視窗。該方法通常用於為 tkinter 視窗指定 transparentcolor alpha、disabled、fullscreen、toolwindowtopmost等屬性。

示例

#Import the tkinter library
from tkinter import *

#Create an instance of tkinter frame
win = Tk()

#Set the geometry
win.geometry("650x250")

#Add a text label and add the font property to it
label= Label(win, text= "Hello World!", font=('Times New Roman bold',20))
label.pack(padx=10, pady=10)

#Create a fullscreen window
win.attributes('-fullscreen', True)

win.mainloop()

輸出

執行以上程式碼將在全屏視窗中顯示視窗,透過按 Alt + F4 鍵可以關閉該視窗。

更新時間:2021-3-26

14K+ 次瀏覽

開啟你的職業

完成課程即可獲得認證

開始
廣告