暂时用一个按钮替换整个 GUI?

Temporarily replace entire GUI with a Button?

如何让 tkinter Button 暂时完全填充整个 gui,然后在按下所述按钮后,return 恢复到之前的状态。

我尝试将按钮设置为我的 "highest level" 框架并使用扩展和填充配置设置,这使 Button 相当大,但最终它只填充了我底部的 1/3贵.

... other instantiations...

#Initialization of button in gui as whole
toggleBacklightButton = Button(patternOptionFrame,text="Screen Light",
                               font=('calibri',(10)),relief="raised",
                               command=toggleBacklight)
toggleBacklightButton.grid(row=0,column=3)

... other code...

#Function that the button press calls.
def toggleBacklight():
    global backlight_toggle
    backlight_toggle = not backlight_toggle
    if backlight_toggle is True:
        # Button should be as it was when instantiated AND back light
        # is on / all other ~20 widgets are also where they belong.
        os.system(
            "sudo sh -c 'echo \"0\" > /sys/class/backlight/rpi_backlight/bl_power'")
    else:
        # Button should fill entire screen for ease of access when
        # screen is black / all other ~20 widgets are hidden.
        os.system(
            "sudo sh -c 'echo \"1\" > /sys/class/backlight/rpi_backlight/bl_power'")

... other functions...

该按钮确实可以切换我的触摸屏显示,但是,我不知道如何在屏幕背光关闭时让它占据整个屏幕。

Tkinter 通常不允许小部件完全重叠 - 让您的按钮变大只会将其他小部件推开,它永远不会真正覆盖它们。在极少数情况下,您 想要重叠,只有 .place() 几何管理器可以做到。使您的按钮成为 window 本身的直接子按钮,然后执行:

toggleBacklightButton.place(x=0, y=0, relwidth=1.0, relheight=1.0)

让它接管window,然后:

toggleBacklightButton.place_forget()

摆脱它。

如果您想使用重叠小部件,请在框架内构建所有内容,并将您的按钮放置在框架的同一网格位置。

像这样:

import tkinter as tk


root = tk.Tk()

def action():
    btn.destroy()

root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)

frame = tk.Frame(root)
frame.grid(row=0, column=0, sticky="nsew")
tk.Label(frame, text="some random label").pack()

btn = tk.Button(root, text="Some big button", command=action)
btn.grid(row=0, column=0, sticky="nsew")

root.mainloop()