混水摸魚

[ Python ] GUI Tkinter 使用按鈕開啟/關閉 全螢幕

python3 程式練習 GUI Tkinter 使用按鈕開啟/關閉 全螢幕

安裝 tkinter gui 指令
sudo apt-get install python3-tk


import tkinter as tk
from tkinter import ttk

root = tk.Tk()
#root.attributes('-zoomed',True)保有控制項的全螢幕

root.attributes('-fullscreen',True)
label=ttk.Label(root,text="Hello world")
label.pack()

#------關閉全螢幕----開始
btn_close_full = ttk.Button(root,text='關閉全營幕')
btn_close_full.pack()

def on_close_full():
    root.attributes('-fullscreen',False)

btn_close_full.config(command=on_close_full)
#-------關閉全螢幕----結束


#-------開啟全螢幕----開始

btn_open_full = ttk.Button(root,text='開啟全營幕')
btn_open_full.pack()

def on_open_full():
    root.attributes('-fullscreen',True)

btn_open_full.config(command=on_open_full)

#-------開啟全螢幕----結束

root.mainloop()

Leave a Comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *